Are there any guidelines regarding, choosing pointer vs non-pointer
member variables for a class
Yes, I am sure you can find hundreds of "guidelines" of that sort. Most
likely they are going to be tied to "associativity" and "containment"
relationships. Learn about those, [...]
Richt. There are many different ways of how some inter-object
relationship can be implemented:
class sub {...};
class foo1 { sub real_sub_object; ... };
class foo2 { sub* stupid_pointer; ... };
class foo3 { vector<sub> vect; ... };
class foo4 { unique_ptr<sub> up; ... };
...
Especially in the presence of neat little building blocks like
standard containers and unique_ptr I think the number of good reasons
why somebody should implement an "is-part-of" or "is-made-up-out-of"
relationship (containment) with a raw pointer (see foo2) is
approaching zero. A raw pointer basically means association. If you
want to use raw pointers to model containment you also have to
"override" the class' default copy semantics by providing custom or
explicitly disabling copy ctor, assignment operator and dtor. IMHO,
it's best to avoid it if possible. Let other, smaller building blocks
handle all the necessary management or use the objects as "real data
members" in these cases.
Cheers!
SG