Why is there still no super in C++?

Asked 1 years ago, Updated 1 years ago, 129 views

Personally, like the next chord, I am writing super with typedef <Base> super; and there is no problem.

You can also call the constructor of the parent class with super() You can write namespace like super:: And even children can redefine it and keep using it Why doesn't C++ make super a standard?

class Derived : public Base
{
   public :
    typeef Base super; //can be in protected or private area
    // Other
} ;

Derived(inti, intj): super(i), J(j) // constructor callable
{}

void Derived::foo()
{
   super::foo(); //namespace available
}

class DerivedDerived : public Derived
{
   public :
    typeef Derived super; // Can be used even if inherited in inheritance.
    // Other
} ;

void DerivedDerived::bar()
{
   super::bar(); //Derived:::bar call
   calling super::super::bar; //Base::bar
}

Why doesn't C++ have super() when it can be used so well? What I want to ask is

c++ coding-style

2022-09-22 10:57

1 Answers

The discussion of super is almost over, and it should probably not be registered as a standard.

I hope it's written in Bjarne Strustrup's Design and Evolution of C++ When creating the C++ standard for the first time, the ISO C++ Standard Commission said it had thought about the super keyword.

Dag Bruck suggested calling the parent class "inherited", when ambiguity became an issue in multiple inheritance.

Dag Buck argued that this function was feasible, technically stable, and could be used in multiple inheritance, but the agency decided it wasn't worth the money.

We later proved that writing typedef like Michael Tiemann's question was not too bad, and this discussion ended.

It's not 100%, but super will probably not be officially supported


2022-09-22 10:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.