In Java, instead of using the scope operator, super is used ex:
C++ -> GenericBase::SomeVirtualFunction();
Java -> super.someVirtualMethod();
Is there something like this in C++ or does this not make sense in C++ because of multiple inheritance?
Thanks
There is a convention of defining a super typedef in every class.
Microsofts compilers have (rejected by C++ standard commitee) extension __super.
Edit: Super may confuse readers of code. Because of multiple inheritance in C++ it is better to be more explicit. Multiple inheritance is already complex. There was AFAIK discussion about usefulness of super for templates that calmed down after it was realized that anyone can typedef super if they need it.
The typedef trick in Martin's link works quite well (and that's partial reason that's why C++ doesn't have super or inherited keywork AFAIR.) The only thing we need to care about is that the typedef should be in private section. Don't put it in protected or public section, otherwise, an derived class may wrong use the typedef to refer to its grandparent rather than its parent.
There's no such thing in C++, although you can provide your own typedef
:
struct Derived : Base
{
typedef Base super;
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With