0

I am Learning C++. I have seen few examples where an object was created inside another class definition as shown below.

Class A {
Public:
    A();
}
Class B{
Public:
    B();

Private:
    A a;
}

In there any advantage of creating an object inside another class definition instead of inheriting the class(Inheriting class A in class B in the above example). I have seen similar example at https://www.includehelp.com/cpp-programs/create-an-object-of-a-class-inside-another-class-declaration.

Ravi A
  • 421
  • 2
  • 9
  • 21

0 Answers0