[BOOST CORE C++ Feature] The super or base keyword for C++

Hello, i was wondering if it makes sens to add the well known super or base keyword to the C++ language in a generic way. Here I have a simple example on how it would make inherited base or super class overloaded function calls easier. Example 1: class A { public: virtual void print() { std::cout << "A" << std::endl; } }; class B : public A { public: virtual void print() { std::cout << "B" << std::endl; std::cout << "super call "; A::print(); } }; class C : public B { public: virtual void print() { std::cout << "C" << std::endl; std::cout << "super call "; B::print(); } }; int main(int argc, char* argv[]) { A a; B b; C c; a.print(); // Prints A b.print(); // Prints B and super call A c.print(); // Prints C and super call B super call A return 0; } Adding a template class superable would avoid one to write the explicit base or super class name. Example 2: namespace boost { template<typename T> class superable : public T { public: typedef T super; // C++ and java style typedef T base; // C# style }; } class A { public: virtual void print() { std::cout << "A" << std::endl; } }; class B : boost::superable<A> { public: virtual void print() { std::cout << "B" << std::endl; std::cout << "super call "; super::print(); // C++ and java style call } }; class C : boost::superable<B> { public: virtual void print() { std::cout << "C" << std::endl; std::cout << "super call "; base::print(); // C# style call } }; int main(int argc, char* argv[]) { A a; B b; C c; a.print(); // Prints A b.print(); // Prints B and super call A c.print(); // Prints C and super call B super call A return 0; } If somebody could add this to the core boost library, that would be great. Sincerely yours, Max

2011/4/29 Max Hölzer <max.hoelzer@yahoo.com>:
Adding a template class superable would avoid one to write the explicit base or super class name.
Unfortunately, this breaks down once you get to templates: template <typename T> class Foo : superable<typename Bar<T>::type> { // the base is dependant, so you still have to typedef typename superable<typename Bar<T>::type>::super super; }; So IMHO the question is whether class C : boost::superable<B> { is really superior to class C : B { typedef B super; and I'd have to say no. ~ Scott
participants (2)
-
Max Hölzer
-
Scott McMurray