I had the same need, and I ended up with this rather manual approach:
class A { public: void fooMutable(void) {} void fooConst(void) const {} }; class B : private A { public: using A::fooConst; const A& getParent(void) const { return *this; } }; void fooParent(const A&) {} int main(void) { auto b = B{}; b.fooConst();
Note that the using keyword will not work with const / mutable overloads:
class A { public: void foo(void) {} void foo(void) const {} }; class B : private A { public: using A::foo;
To solve this problem, you can independently override the function and call the parent:
class B : private A { public: void foo(void) const { A::foo(); } };
This can take quite a while if you inherit a large hierarchy, but if it is for a small class, it should be very reasonable and quite natural for the user.
source share