is this method override? ,
Code:#include<iostream> using namespace std; class A { protected: void show() { cout<<"A"; } }; class B:public A { public: void show() { cout<<"B"; A::show(); } }; int main() { A *a = new B(); a->show(); // tries to call A::show() getchar(); return 0; }
a->show() is calling A::show() rather than B::show() , so i suspect this isnt method override
however if it isnt, this means B has not overriden A's show(), and hence B has 2 show() methods with same signature name and return type, but different access specifiers
so i tried this:-
now compiler reports error in overloading show() because both have same signature, that means 2 same functions cannot even exist in different access specifiersCode:#include<iostream> using namespace std; class A { protected: void show() { cout<<"A"; } public: void show() { cout<<"B"; } }; int main() { A *a = new A(); a->show(); getchar(); return 0; }
both conclusions are contradicting each other
which is correct?



LinkBack URL
About LinkBacks




Want to add some