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();
If you want an object of class B in A, then you must use the second. The first doesn't give you an object of type B in A, it gives you an object of type B*
in A.
The second is also more convenient for almost all purposes. Only use a pointer when you have to, and even then resource-handling is more convenient with a smart pointer rather than a B*
.