0
#include <iostream> using namespace std; class A{ public: void f1(); }; class B : public A{ public: virtual void f1(); } int main() { A * obj = new B; obj.f1(); } Ques: can we write virtual before an overridden function from the base class?? if yes which f1() should it call base class f1() or derived class f1()???
Mine ans is coming as base class f1()... but since we are using virtual infront of f1() is should be late binding..where as here it is doing early binding...
1 Odpowiedź
0
No, we can not write virtual before an overridden function from the base class.
More information are in the virtual functions and abstract classes lessons.