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();
In this scenario, the non-pointer version is more convenient. You don't need to worry about invoking delete
at the correct time, and therefore you don't need to worry about destructors, copy constructors and copy assignment operators.
In general, you should avoid dynamically-allocated memory as much as possible.