S
Srini
Hello,
I've had this long lasting doubt. When a sub-class re-defines a
function that's in its superclass, it hides the superclass function.
class A {
public:
void foo(int) { }
};
class B : public A {
public:
void foo(std::string) { }
};
B obj;
obj.foo(10); // Error, no matching function B::foo(int)
Here B::foo(std::string) hides A::foo(int). So, if I want to bring
A::foo(int) into visibility, I've to put a using directive.
class B : public A {
public:
using A::foo; // bring A::foo(int) into scope here
void foo(std::string) { }
};
Now the normal overload function call resolution would happen. In that
case, why is the following not an error?
class A {
public:
void foo(int) { }
};
class B : public A {
public:
using A::foo;
void foo(int) { }
};
B obj;
obj.foo(10); // This would call B::foo(int)
Should this not result in a compile error because there are 2 functions
with the same signature?
Thanks,
Srini
I've had this long lasting doubt. When a sub-class re-defines a
function that's in its superclass, it hides the superclass function.
class A {
public:
void foo(int) { }
};
class B : public A {
public:
void foo(std::string) { }
};
B obj;
obj.foo(10); // Error, no matching function B::foo(int)
Here B::foo(std::string) hides A::foo(int). So, if I want to bring
A::foo(int) into visibility, I've to put a using directive.
class B : public A {
public:
using A::foo; // bring A::foo(int) into scope here
void foo(std::string) { }
};
Now the normal overload function call resolution would happen. In that
case, why is the following not an error?
class A {
public:
void foo(int) { }
};
class B : public A {
public:
using A::foo;
void foo(int) { }
};
B obj;
obj.foo(10); // This would call B::foo(int)
Should this not result in a compile error because there are 2 functions
with the same signature?
Thanks,
Srini