avoid-hiding-inherited-names/prog1.cc - Class B redefines one of the functions, and expects to inherit the other - problems. | Lecture 5 - slide 9 : 40 Program 2 |
// For exercise. // We override one of the overloads in class B. // Is the other - vf(double) - inherited? #include <iostream> #include <string> using namespace std; class A { private: double a; public: virtual void vf(double d){ // Virtual vf(double) cout << "virtual vf(double) in A: " << d << endl; } virtual void vf(){ // Virtual vf() cout << "virtual vf() in A" << endl; } }; class B : public A { private: double b; public: void vf() override { // Virtual vf() overrides A::virtual vf() cout << "virtual vf() in B" << endl; } // It is expected that A::vf(double) is inherited. // BUT THERE ARE PROBLEMS - COMPILER ERROR. }; int main(){ B *b = new B(); b->vf(); b->vf(5.0); // Compiler error: no matching function for call to B::vf(double) }