我的编码风格包括以下习语:
class Derived : public Base
{
public :
typedef Base super; // note that it could be hidden in
// protected/private section, instead
// Etc.
} ;
Run Code Online (Sandbox Code Playgroud)
这使我能够使用"super"作为Base的别名,例如,在构造函数中:
Derived(int i, int j)
: super(i), J(j)
{
}
Run Code Online (Sandbox Code Playgroud)
或者甚至在其重写版本中从基类调用方法时:
void Derived::foo()
{
super::foo() ;
// ... And then, do something else
}
Run Code Online (Sandbox Code Playgroud)
它甚至可以链接(我仍然可以找到它的用途):
class DerivedDerived : public Derived
{
public :
typedef Derived super; // note that it could be hidden in
// protected/private section, instead
// Etc.
} ; …Run Code Online (Sandbox Code Playgroud)