I recently took a C class, and one of my TAs mentioned that in creating list structures in C, the items should be stored as pointers in one another. For example, your list would have a first and last entry, and they would have pointers to the next and/or previous items in the list. He went further to say that when using structures in C, it is typically for efficient to use pointers to structures rather than the structures themselves.
I'm wondering if, in C++, I should use pointers to my objects rather than the instances directly. In one particular case, I have an object tree, where there is a root object with vectors of other objects of the same or a derived types, and those may or may not contain more objects of the same or a derived type, etc.
I kind of have two questions here, one about a general convention or rule of thumb (should pointers to object be used instead of object directly?), and for my particular project (should I store pointers to the sub-objects in the vectors of my object tree instead of storing the instances in the vectors?).
It sounds like he is talking about making a linked list, not structures in general.
As for:
it is typically for efficient to use pointers to structures rather than the structures themselves.
That is only true when passing the structures to functions as you avoid copying...if you are just making a structure and using it, then using a pointer instead adds a useless dereference which will just waste some time.
Not unless you need the pointers for something, like polymorphism.
1) See above. Generally I would suggest using the least complicated approach, just using pointers everywhere is dumb and adds possibility of errors.
2) No. There would be no point unless you need the pointers for something else.