I'd like to alias a method of a base class in a derived method in C++ -- i.e. change only the name, not the signature.
The method's name is clear enough in its original scope (in the base class), but becomes ambiguous or misleading in the derived class. Thus, the obvious mitigation is to create an alias for the method in the base class. However, the long list of parameters the method takes is in flux as the derived class is being refined & retested. I'd like to avoid the boilerplate data entry task of re-typing the method signature, and alias it in a simpler manner, much like I can do with the 'using' directive for an inherited specialized constructor.
Simple example:
struct Person { int ID; void virtual sit() {}; void virtual walk() {}; void virtual run(int speed, int duration, int stride) {}; //method name in unambiguous in this scope Person(int id) : ID(id) {} //specialized c'tor }; struct Politician : Person { void speak() {}; void campaign() {}; //use this to 'run' for office //'sit' and 'walk' are clear enough, but 'run' is ambiguous in this scope, so alias it to 'sprint' void sprint(int speed, int duration, int stride) { Person::run(speed, duration, stride); } //the above works, but is a boat-load of boilerplate that I'd like to avoid using Person::Person; //use Person c'tor (avoids boilerplate) //using sprint = Person::run; //doesn't work - "'run' in 'struct Person' does not name a type" }; (Also consider a virtual class that inherits from multiple base classes, with one or more identically-named base-class methods. Such is my real-world application that I boiled down into this simpler example of the root need.)
Surely there is an easier way to create an alias for an unchanged inherited method, right?
sprintin not virtual, and you call base method fromsprintthat won't works as expected if you add a derived class toPoliticianYou might argue that this can be fixed. Yes but given you didn't got it right, it already prove that your idea is error-prone... Also, given the argument of run method, it is clear its purpose so you don't need renaming here.Person* p = new Politician(...); p->run(...);andPolitician* p = new Politician(...); p->run(...);each to call?Politician* p = new Person(...):won't compile.Penguinis inherited fromBird, butPenguincan't fly.