Having
- a BASE class defining a virtual method
- a DERIVED class which defines a virtual method with the same name, but different signature
the compiler complains that it cannot find the correct function in the BASE class when called from another class using a pointer to the DERIVED class.
Example (Constructors etc omitted):
class BASE {
public: virtual int print(std::vector<double>& values);
};
int BASE::print(std::vector<double>& values){
std::cout << "This is the base class!" << std::endl;
}
class DERIVED : public BASE {
public: void virtual print(int a, int b);
};
void DERIVED::print(int a, int b){
std::cout << "This is the derived class from int-method!" << std::endl;
}
class TEST {
public: void testit();
};
void TEST::testit(){
DERIVED derived;
std::vector<double> a;
derived.print(a);
}
The compiler complains with TEST.cpp:30:17: error: no matching function for call to ‘DERIVED::print(std::vector<double>&)
What can I do to overload virtual functions with different signatures in derived classes? For example, this may be useful to add functionality that cannot be available in the BASE class.
print
variant is available forTest::testit
to call.