How are allocated objects inside a struct dynamically created ?
Jul 12, 2011 at 9:40am UTC
If I have :
1 2 3
struct my_struc {
vector<float > my_vector_of_floats;
};
and I create an instance :
my_struc a_instance_of_mystruct = new my_struc;
Where is allocated the vector?
Have I to write :
vector<float > * my_vector_of_floats;
inside the struct, to let dinamyc memory use ?
Thanks
Last edited on Jul 12, 2011 at 9:41am UTC
Jul 12, 2011 at 9:41am UTC
No, it will work fine without a pointer. The vector is allocated in the space for the structure. It is basically just a bunch of variables in a row in memory.
Jul 12, 2011 at 11:20am UTC
A vector itself has pointers to a bunch of memory, the vector itself does not contain the memory. This is a common misconception.
Topic archived. No new replies allowed.