I know this looks like a silly question, but using object oriented stuff with templates in C++ is really troublesome.
For example, Foo is the base class:
template <typename T>
class Foo {
public:
virtual void Method1() { }
virtual void Method1(int a) { }
virtual void Method2() { }
virtual void Method2(int a) { }
//... lots of other methods
};
Is there something like:
template <typename T>
class Bar : public Foo<T> {
public:
using Foo<T>::*; //redefine all inherited methods from Foo
virtual void Method1(int a) { }
virtual void Method2(int a) { }
//other methods overloading..
};
Instead of:
template <typename T>
class Bar : public Foo<T> {
public:
using Foo<T>::Method1
using Foo<T>::Method2
//... lots of other methods
virtual void Method1(int a) { }
virtual void Method2(int a) { }
//other methods overloading..
};
So we can do:
int main() {
Bar<int> b;
b.Method1();
b.Method2();
//... lots of other methods
//This obviously works without the 'using' keyword:
Foo<int>* f = &b;
f->Method1();
f->Method2();
//etc
return 0;
}
No, there is no functionality like that but it usually isn’t needed. What you intend to do with
usingis already provided by the basic inheritance mechanism.You need to use
usingif overloads in the deriving class hide methods from the base class or if you want to change the access mode, but not in general:Note that you can still call
A::h()through aBinstance because nothing hides it.