Hello,
Consider the following examples:
template<typename A, typename B, typename C>
class BaseClass
{
public:
virtual void foo()
{
/*code*/
}
};
class SomeClass : public BaseClass < int, float, SomeOtherBaseClass >
{
public:
virtual void foo()
{
/*code before foo*/
BaseClass<int, float, SomeOtherBaseClass>::foo();
}
};
Problems:
For virtual functions if you have to write the base class in order to call the implementation.
This can be quite a pain if the base class is templated, or the name is very long.
Also if you change the base class you end up having to change all the places you used it.
Proposal:
Having using base_t defined in each class with the type of the base class:
using base_t = BaseClass<int,float,SomeOtherBaseClass>;
This will simplify writing base foo calls and because it's automatic all the problems described above will disappear.
One remaining problem is with multiple inheritance. For this i propose the use of base_t with a N being the index of the class used.
template <std::size_t N>
using base_t = typename std::tuple_element<N, std::tuple<BaseClass1, BaseClass2, BaseClass3>>::type;
Using base_t<N> is not very intuitive but i don't see how this can solved at this point.
Here is how it looks:
class SomeClass : public BaseClass<int,float,SomeOtherBaseClass>
{
public:
using base_t = BaseClass<int,float,SomeOtherBaseClass>; //this line could be defined automatically by the compiler saving the user the need to write redundant code.
virtual void foo()
{
/*code before foo*/
base_t::foo();//much easier to read and write
}
};
Alternative:
One alternative is to write it yourself for every class but when you change the base type you have to change the using definition also.