Some advantages of pointer member:
- The child (MyOtherClass) object can have different lifetime than its parent (MyClass).
- The object can possibly be shared between several MyClass (or other) objects.
- When compiling the header file for MyClass, the compiler doesn't necessarily have to know the definition of MyOtherClass. You don't have to include its header, thus decreasing compile times.
- Makes MyClass size smaller. This can be important for performance if your code does a lot of copying of MyClass objects. You can just copy the MyOtherClass pointer and implement some kind of reference counting system.
Advantages of having the member as an object:
- You don't have to explicitely write code to create and destroy the object. It's easier and and less error-prone.
- Makes memory management more efficient because only one block of memory needs to be allocated instead of two.
- Implementing assignment operators, copy/move constructors etc is much simpler.
- More intuitive