B
bb
Hi,
Why overriding "virtual void f(std::string)" as follows hides the "non-
virtual void f(int)" ?
compilation error C2664: 'D::f' : cannot convert parameter 1 from
'int' to 'std::string'
I know it will work if I bring it to the scope by B::f(). I just would
like to know why does it hide just because am implementing a virtual
method.
Thanks in advance.
------ code starts -------
class B {
public:
void f(int i) {
std::cout << "B::f(int)" << std::endl;
}
virtual void f(std::string s) {
std::cout << "virtual B::f(std::string)" << std::endl;
}
};
class D : public B {
public:
void f(std::string s) {
std::cout << "D::f(std::string)" << std::endl;
}
void g() {
std::cout << "D::g()" << std::endl;
f(10); // works if I make it B::f(10)
}
};
------ code ends -------
Why overriding "virtual void f(std::string)" as follows hides the "non-
virtual void f(int)" ?
compilation error C2664: 'D::f' : cannot convert parameter 1 from
'int' to 'std::string'
I know it will work if I bring it to the scope by B::f(). I just would
like to know why does it hide just because am implementing a virtual
method.
Thanks in advance.
------ code starts -------
class B {
public:
void f(int i) {
std::cout << "B::f(int)" << std::endl;
}
virtual void f(std::string s) {
std::cout << "virtual B::f(std::string)" << std::endl;
}
};
class D : public B {
public:
void f(std::string s) {
std::cout << "D::f(std::string)" << std::endl;
}
void g() {
std::cout << "D::g()" << std::endl;
f(10); // works if I make it B::f(10)
}
};
------ code ends -------