Using C++ Vectors to create multiple rectangles from a class

Hi,

New to C++ and oF. I created a class called Rectangle where I have a ofRect(). Now, I am aware that if I want to use arrays to create multiple objects from a class I would have to use a vector. So this is what I have so far but it throws me a warning:

  
testApp.h  
  
    vector < Rectangle > myRects;   

  
 testApp.cpp  
  
void testApp::draw(){  
      
    for ( int i = 0; i < 6; i++){  
          
        myRects[i].draw();  
    }  
  
  

It does not let me load the file and it gives me this warning that points me to my original Rectangle.cpp where I draw my element.

Any suggestion is more than welcome.

![](http://forum.openframeworks.cc/uploads/default/3003/Screen Shot 2013-08-29 at 6.06.48 PM.png)

hi sheva_29

in setup() you should just stuff some elements in your vector via

myRects.push_back(…)
see here -> http://www.cplusplus.com/reference/vector/vector/push-back/

vectors are quite handy for dynamic array thingies
greetings ascorbin

You also should use iterators to loop through a vector. Then you also do not need to set a fixed number (in your example 6) as end value of the loop.

An example can be found here: http://oflog.tumblr.com/post/58340159934/find-cam-by-device-name-instead-of-id-when-using

These are all helpful suggestions. I figured it out! the problem was that I was not adding the Rectangle in the setup and the pushing it back to the Vector.

Best,

M