I have a base class and there are few classes being derived from it. I have not written any copy constructor in the base class, it is using the default one.
So if I write this code:
base* b;
b = new base(*this)
it works fine, but if I write something like this:
base* b;
b = new derive(*this)
it gives me an error for no matching function in the derived class.
Can’t I pass base class’ this pointer to its derived class copy constructor to get it initialized?
Derivedcopy constructor takesconst Derived &as it’s argument. You can’t useconst Base &as an argument.You are trying to do:
In order to construct
DerivedfromBaseyou need to provide such constructor yourself: