In Derived
there is a template foo(T)
. There are 2 overloads of foo()
in Base
.
struct Base
{
void foo (int x) {}
void foo (double x) {}
};
struct Derived : Base
{
template<typename T> void foo (T x) {}
using Base::foo;
};
Now, when foo()
is called with Derived
object; I want to use only Base::foo(int)
if applicable, otherwise it should invoke Derived::foo(T)
.
Derived obj;
obj.foo(4); // calls B::foo(int)
obj.foo(4.5); // calls B::foo(double) <-- can we call Derived::foo(T) ?
In short, I want an effect of:
using Base::foo(int);
Is it possible ? Above is just an example.
using
bringes all overloads into the scope. Just hide it in the derived class, it's a bit more to write but does the job:
struct Derived : Base
{
template<typename T> void foo (T x) {}
void foo(int x){
Base::foo(x);
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With