Just like in the title, how do you call a base class copy constructor from a derived class copy constructor?
Copy constructor is not inherited.
A class can have multiple copy constructors, e.g. both T::T(const T&) and T::T(T&). If some user-defined copy constructors are present, the user may still force the generation of the implicitly declared copy constructor with the keyword default .
When is a Copy Constructor Called in C++? A copy constructor is a member function that initializes an object using another object of the same class. The Copy constructor is called mainly when a new object is created from an existing object, as a copy of the existing object.
The copy constructor is called because you call by value not by reference.
You can specify base initialization in the initialization list:
Derived:: Derived( const Derived& other ): Base( other ) { /* ... */ }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With