What is Shadowing in C++? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is Shadowing in C++?

Class A { public: void f1() cout<<"base f1"; }; Class B:public A { public: void f1() cout<<"derived f1"; }; int main() { B b; b.f1(); } In above if i create object of derived class and call f1 method then it give call to base class f1 and not derived f1. But as per shadowing concept in C++ , if method name in base and derived is same and we are calling that method using derived class object then it will hide the base class method implementation and call derived class method. But why in this scenario it is giving me base class method?

26th Nov 2019, 5:36 PM
Amit chavare
Amit chavare - avatar
1 Answer
0
~ swim ~ updated question please have a look
26th Nov 2019, 5:50 PM
Amit chavare
Amit chavare - avatar