My questions is, suppose we have two classes A and B. I want to have an object of B in class A.
Should I use,
class A
{
public:
A();
Second one is more convenient , because you don't need to manage memory yourself. No new
, no delete
.
If you go with the first one, then you probably have to implement Rule of Three also (in C++03):
Or, Rule of Five (in C++11):
The underlying idea behind this rule is the following:
So unless you've strong reason why you need pointer version (such as in case when you need polymorphic behavior), you must go with the second approach (the non-pointer approach).