The following phrase is part of my coding approach:
class Derived : public Base
{
public :
typedef Base super; // note that it could be hidden in
// protected/private section, instead
// Etc.
} ;
This lets me to use "super" in constructors as an alias for Base, for instance:
Derived(int i, int j)
: super(i), J(j)
{
}
even when the method is used within the overridden version of the base class:
void Derived::foo()
{
super::foo() ;
// ... And then, do something else
}
It can even be chained (although I haven't yet figured out how to utilise that):
class DerivedDerived : public Derived
{
public :
typedef Derived super; // note that it could be hidden in
// protected/private section, instead
// Etc.
} ;
void DerivedDerived::bar()
{
super::bar() ; // will call Derived::bar
super::super::bar ; // will call Base::bar
// ... And then, do something else
}
In any case, I find "typedef super" to be really helpful, for instance, when Base is either verbose or template-based.
Super is really implemented in both Java and C#, where it is named "base" unless I'm mistaken.
But this keyword is absent from C++.
Consequently, I have the following inquiries:
Is this typedef use extremely frequent, uncommon, or never encountered in the code you deal with?
Is this usage of typedef perfectly acceptable (that is, can you see any good or mediocre arguments against it)?
Should the term "super" be encouraged? Should it be somewhat standardised in C++, or is its current use through a typedef sufficien?