The output of this code yields "BASE!". Why hasn't the copy function of derived class been called in this example. They have the same signature and by my reasoning the derived one should be called. What is the problem?
#include <iostream>
using namespace std;
class Base{
virtual void copy(const Base&b){
cout<<"BASE!";
}
public:
Base()=default;
Base(const Base&b){
copy(b);
}
};
class Derived: public Base{
void copy(const Base&b) override{
cout<<"DERIVED";
}
};
int main() {
Derived d;
Derived b(d);
return 0;
}