2

For an example:

class some_base
{
 ... // some valid code
};

class derived : public some_base
{
  ...

  derived& operator=( const derived& that )
  {
    some_base::operator=( that );

    ...

    return *this;
}; 

It'd be good if we were able to use some keyword in a derived's assign operator instead of a some_base qualifier. Compiler knows a type we inherit from so it's not a problem, in my opinion.

So the question is does С++ provides an auxiliary keyword to simplify the coder's life ?

sergs
  • 123
  • 1
  • 12

2 Answers2

3

Compiler knows a type we inherit from so it's not a problem

Unless you derive from multiple base classes - in such case, how would compiler decide which one it is?

So no, there is no such keyword, all you can do is put one into your coding standard.

Jaa-c
  • 5,017
  • 4
  • 34
  • 64
1

Some compilers provide a base class keyword as an extension. It seems that variants of the name super are common, e.g. Visual C++'s __super (I would expect that as an intended plug-in replacement, Intel's compiler also supports __super). But standard C++ provides no such thing, although there was once a proposal.

To achieve about the same, simply define a type alias Base in every class.

In another thread, user Roddy argues that such an alias should be private “to avoid the problem when the 'inherited' is erroneously omitted from a class but a subclass tries to use it”.

Cheers and hth. - Alf
  • 142,714
  • 15
  • 209
  • 331