The following code.
#include <iostream>
using namespace std;
#include <stdio.h>
class mother {
public:
virtual mother* display() {};
};
class daughter : public mother
{
public:
daughter* display()
{
daughter *d1 = new daughter();
std::cout << "This is the daughter" << std::endl;
return d1;
}
void signature()
{
cout<<"I'm the sign"<<endl;
}
};
int main() {
//code
mother *w = new daughter();
daughter *w2 = w->display();
w2->signature();
return 0;
}
Returns an error that daughter w2 cannot be assigned from the return value of w->display(). But from what I know, display is a virtual function. So w->display() should call the daughter variation of the display function, which has a return type of daughter. Then exactly why isn't this working and what could be changed?