I'm rather new to C++ (with Java background) and I'm trying to understand the principles and practices for class designing.
From what I've already read it seems to me that one should prefer having class members as objects to having them as pointers (or references). - Please correct me if this is somehow wrong.
Based on that here's my design (version 1):
class Outer {
    Some_type _member;
    Inner _inner;
};
class Inner {
    Some_type* _ptr_to_outer_member;
};
I am aware that the lifetime of referenced object (Outer._member) needs to be guaranteed to exceed the lifetime of referencing object (Inner) and its pointer _ptr_to_outer_member to avoid dangling pointer. This condition should be satisfied here by the fact that _inner is a composite of _outer and Outer._member is an object member therefore it is always initialized.
Now I certainly don't need Outer to be copyable. Even being movable is not necessarily required since it's not supposed to be moved after everything is set up - although it'd be handy to have it movable when constructing other objects. Anyway with this design when Outer is moved _inner._ptr_to_outer_member gets invalidated. - This can be prevented by disabling copy and move operations for Outer but it kind of feels like it's just working around a bad practice. There's a guideline which says to avoid storing references to stack allocated variables and this case seems to me like it could have similar reasons to be avoided.
An alternative I can see is to heap allocate _member like this (version 2):
class Outer {
    std::unique_ptr<Some_type> _member;
    Inner _inner;
};
class Inner {
    Some_type* _ptr_to_outer_member;
};
Outer is now movable and non-copyable which is what I want but it's for the cost of heap allocating _member which is against the guideline about preferring object members.
So it gets me to the question: Are there any guidelines on this? I mean something like to use pointer to object as a members when you want to share the object (as in design version 2) - this would probably make the most sense to me (unless I'm missing something). Or to just disable moving for such objects (as in design version 1) and deal with it as it's non-movable.
Or is there something fundamentally wrong with the examples?
Thanks in advance for any insights on this.
 
    