How do you declare multiple objects at once? (C++)
Is there some way to declare, maybe in a for loop or something, multiple class objects?
I.E.
For(i=1, i != 10, i++)
{
objectclass object(i);
}
Is this possible, or do you have to manually declare each object?
Quote:Original post by DOS4dinner
For(i=1, i != 10, i++)
{
objectclass object(i);
}
Assuming you meant to write ; instead of , inside the for loop, you would only have created nine objects: 1 2 3 4 5 6 7 8 9.
Anyway, I suggest using a vector:
#include <vector>class objectclass { /* your definition of the class here */ };int main(){ std::vector<objectclass> v; for (int i = 0; i < 10; ++i) v.push_back(objectclass());}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement