I was going through a piece of code as mentioned below and found that the method in child class is non-virtual, still the method is getting called by its base class pointer. Can anybody tell me the reason why....??
class Base {
virtual void method() { std::cout << "from Base" << std::endl; }
public:
virtual ~Base() { method(); }
void baseMethod() { method(); }
};
class A : public Base {
void method() { std::cout << "from A" << std::endl; }
public:
~A() { method(); }
};
int main(void) {
Base* base = new A;
base->baseMethod();
getchar();
return 0;
}
Output - from A