Until 'super' is implemented in c++, I'm looking for a way to emulate it myself. Motivation: Here's a typical scenario:
class A
{
void SomeMethod();
}
class B : public A
{
void SomeMethod() override;
}
void B::DoSomething()
{
A::SomeMethod();
}
All is well, until someone inserts a class in between:
class C : public A
{
void SomeMethod() override;
}
and changes inheritance:
class B : public C {...}
In most cases I'd like the immediate base class to be called, which is not going to happen unless I explicitly replace all A:: calls with C:: calls.
A 'super' keyword would be of great use here, where it means: "use the immediate base, but issue a compiler error if ambiguous".
Reading some suggestions, I attempted to define as follows:
class A
{
void SomeMethod();
protected:
using super = A;
}
class C
{
void SomeMethod();
protected:
using super = C;
}
void B::DoSomething()
{
super::SomeMethod();
}
However A::SomeMethod() was called instead of C::SomeMethod()...
How does the compiler treat multiple aliases with the same name?
How can I fix this?
EDIT: the suggested other question is an old one where the solutions might by improved using modern c++.