What's going on here -- why does this not compile?
#include <iostream>
class Base {
void print(double d) {
std::cout << "Base: " << d << std::endl;
}
};
class Derived : public Base {
void print(std::string const & str) {
std::cout << "Derived: " << str << std::endl;
}
};
int main(int argc, char* argv[]) {
Derived d;
d.print(2.);
d.print("junk");
}
(Errors in both MinGW and VC11 with something equivalent to No conversion from double to std::string
.)
If I change the name of the print function in Derived
, it compiles successfully, so clearly Derived::print(string const &)
is masking Base::print(double)
somehow. But I was under the impression that the function signature included the argument type(s) and so this masking should occur here. Is that not correct in the case of base class methods?