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


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:

    vector < Rectangle > myRects;   

void testApp::draw(){  
    for ( int i = 0; i < 6; i++){  

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.

![]( 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

see here ->

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:

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.