title: array of object in C++ in sfml
body: <p>I am trying to use vectors in sfml C++ and I am semi-failing because I am not able to create a vector consisting of 4 RectangleShapes :(
  I am skipping some lines of the code which are not causing the problem</p>
  
  <p>This is the code which is working but it is least optimized in my opinion</p>
  
  <pre><code>#include &lt;SFML/Graphics.hpp&gt;
  #include &lt;SFML/Audio.hpp&gt;
  #include &lt;vector&gt;
  #include &lt;iostream&gt;
  #include "mainCharacter.h" // it consists the mainCharacter class
  
  class classBackground{
  public:
      sf::Texture texture;
      sf::Sprite image;
      sf::RectangleShape rectTopBorder,rectBotBorder,rectLeftBorder,rectRightBorder;
      std::vector&lt;sf::RectangleShape&gt; rect;
      classBackground(){
          texture.loadFromFile("wagon.png");
          image.setTexture(texture);
          image.setPosition(300,250);
          rectTopBorder.setSize(sf::Vector2f(230,5));
          rectTopBorder.setPosition(image.getPosition());
          rectTopBorder.move(0,60);
          rectBotBorder.setSize(sf::Vector2f(230,5));
          rectBotBorder.setPosition(image.getPosition());
          rectBotBorder.move(0,225);
          rectLeftBorder.setSize(sf::Vector2f(5,170));
          rectLeftBorder.setPosition(image.getPosition());
          rectLeftBorder.move(0,60);
          rectRightBorder.setSize(sf::Vector2f(5,170));
          rectRightBorder.setPosition(image.getPosition());
          rectRightBorder.move(225,60);
          rect.push_back(rectTopBorder);
          rect.push_back(rectBotBorder);
          rect.push_back(rectLeftBorder);
          rect.push_back(rectRightBorder);
      }
  };
  
  //in the main function
  classMainCharacter mainCharacter; ///another class which has collision detection
  classBackground background;
  ///in the loop
      for(int i = 0; i&lt;=3; i++){
          mainCharacter.collision(background.rect[i]); ///colision is a function in the mainCharacter class (detects collision)
      }
  </code></pre>
  
  <p>And this is the code which I want to work but my game is crushing :(</p>
  
  <pre><code>#include &lt;SFML/Graphics.hpp&gt;
  #include &lt;SFML/Audio.hpp&gt;
  #include &lt;vector&gt;
  #include &lt;iostream&gt;
  #include "mainCharacter.h" // it consists the mainCharacter class
  
  class classBackground{
  public:
      sf::Texture texture;
      sf::Sprite image;
      std::vector&lt;sf::RectangleShape&gt; rect; // it doesn't work if I write rect(4) or rect = {rect1,rect2,rect3,rect3} or even rect(4)={rect1,....}
      classBackground(){
          texture.loadFromFile("wagon.png");
          image.setTexture(texture);
          image.setPosition(300,250);
          rect[0].setSize(sf::Vector2f(230,5));
          rect[0].setPosition(image.getPosition());
          rect[0].move(0,60);
          rect[1].setSize(sf::Vector2f(230,5));
          rect[1].setPosition(image.getPosition());
          rect[1].move(0,225);
          rect[2].setSize(sf::Vector2f(5,170));
          rect[2].setPosition(image.getPosition());
          rect[2].move(0,60);
          rect[3].setSize(sf::Vector2f(5,170));
          rect[3].setPosition(image.getPosition());
          rect[3].move(225,60);
      }
  };
  
  //in the main function
  classMainCharacter mainCharacter; ///another class which has collision detection
  classBackground background;
  ///in the loop
      for(int i = 0; i&lt;=3; i++){
          mainCharacter.collision(background.rect[i]); ///colision is a function in the mainCharacter class (detects collision)
      }
  </code></pre>
  
  <p>what am I doing wrong? :(
  I tried to defined the rects before vector and then inserting into the vector but it also doesn't work (in such way vector&lt;...> rect = {......}).</p>