Hi,
can you explain me why:
int main (int argc, char * const argv[]) {
Parent* p = new Child();
p->Method();
return 0;
}
prints "Child::Method()", and this:
int main (int argc, char * const argv[]) {
Parent p = *(new Child());
p.Method();
return 0;
}
prints "Parent::Method()"?
Classes:
class Parent {
public:
void virtual Method() {
std::cout << "Parent::Method()";
}
};
class Child : public Parent {
public:
void Method() {
std::cout << "Child::Method()";
}
};
Thanks, Etam.