A vector of class that has vectors, can it be done?

I know an array must know the total size of objects it holds, but what about vectors?

If I have a class, named Widget, and that class has vectors for data members, can I make a vector of that class? If so, is there anything I should do, or be on the lookout for?

I ask because I am basically making a variable list of variably sized objects, and I don't know whether to expect memory issues.

I am still building the code, so I haven't tested it yet, I would just rather head off problems rather than react to them afterwards.
what about vectors
Vector is dynamical array. When you need to add new elements it will grow if does not enough capacity.
They are not variably sized objects. The vectors in each object may have different numbers of elements in them but the sizeof the objects are all the same. Just like how pointers are not the sizeof the thing they point to.
Yes, but even a pointer has a size, so adding more pointers should take more space.

Now, there are ways to avoid that, but I don't know if vectors use those methods, as it makes things much more complicated (unless something I don't know makes it easier, not unlikely I guess), hence the idea that it might not take the complicated route.

Not sure how vectors work, but if it is fine then cool. Thanks.
I didn't explain myself very well.

Imagine having a pointer to an array, it wouldn't matter how many elements are in the array the pointer stays the same size. Now imagine having many of those pointers with differnent array sizes. The pointers are all the same size.

so in answer to your question does a vector need to know the size of it's elements. It does, but in your example all the objects are the same size.
Topic archived. No new replies allowed.