C ++ polymorphism and virtual function

Is it possible to call the virtual function foo (int) from B without using what is done in the comment?

class A { public: virtual void foo ( char * ) { } virtual void foo ( int ) { } }; class B : public A { public: void foo ( char * ) { } //void foo ( int i ) { // // A::foo(i); //} }; B b; b.foo(123); // cannot convert argument 1 from 'int' to 'char *' 
+5
source share
1 answer

Yes it is possible. The problem here is that the function B::foo(char*) hides the name of the inherited function A::foo(int) , but you can return it to area B with the declaration using :

 class B : public A { public: void foo ( char * ) { } using A::foo; }; 
+8
source

Source: https://habr.com/ru/post/1202360/


All Articles