Hi All,

Please find the below code and please elaborate how derived class default copy constructor is calling base class copy constructor which is implemented by the base class.

class X
{
         X( const X& x );
}
 
class Y ; public X
{
}

class Z
{
      void fun( ) 
      {
         Y y1; 
         Y y2 = y1; 
      }
}

At the expression Y y2 = y1; it is calling X( const X& x ) ( meanse from Y's default copy constructor Base class Implemented Copy constructor. I thought of it will call Base class's default copy constructor. Can you please how this is happening.

Many Thanks
Nari

Because Y inherits from X. Due to the inheritance, when you have an object of Class Y, you also have an object of Class X that is embedded within the Y object.

When you make a copy of the Y object, you are also making a copy of the embedded X object.