Say I have the following classes:
template <class T>
class Base {
protected:
T theT;
// ...
};
class Derived : protected Base <int>, protected Base <float> {
protected:
// ...
using theInt = Base<int>::theT; // How do I accomplish this??
using theFloat = Base<float>::theT; // How do I accomplish this??
};
In my derived class, I would like to refer to Base::theT using a more intuitive name that makes more sense in the Derived class. I am using GCC 4.7, which has pretty good coverage of C++ 11 features. Is there a way of using a using statement to accomplish this kind of how I tried in my example above? I know that in C++11, the using keyword can be used to alias types as well as eg. bring protected base class members into the public scope. Is there any similar mechanism for aliasing a member?
Xeo’s tip worked. If you are using C++ 11, you can declare the aliases like so:
If you don’t have C++11, I think you can also initialize them in the constructor:
EDIT:
The slight annoyance is that you can’t initialize the the value of those aliased members until the main body of the constructor (ie, inside the curly braces).