Thanks miteshpandey,


I think your point is if owns the Goo, using class type other than pointer/reference type is better. Right?

But how do you define or judge whether "owns" or not? In my perpective, I think it means managing the lifecycle (create and destroy), I am not sure whether you have different ideas about what means own? :-)

Quote Originally Posted by miteshpandey
I think it actually depends on what is Foo and what is Goo and what you are trying to achieve.

In your example the Goo object actually owns the Foo object. But if actually Foo doesn't belong to Goo and Goo only needs accessing Foo then you can use a pointer or a reference.

Pointer can also be used to get an extra level of indirection (pImpl Idiom) and to reduce compilation time.

have a good weekend,
George