tags:

views:

91

answers:

2

Hello,

Is there any way to directly expose some methods of private parent class. In the following example if I have an object of type Child I want to be able to directly call method a() of its parent, but not b(); Current solution spawns a lot of boilerplate code especially if there are a lot of arguments.

class Parent {
    public:
        void a(int p1, double p2, int p3, std::vector <int> &p4);
        void b();
    };
class Child : private Parent {
    public:
        void a(int p1, double p2, int p3, std::vector <int> &p4) {
            Parent::a(p1, p2, p3, p4);
            }
   };
+9  A: 

You can use the using declaration.

class Child : private Parent {
    public:
        using Parent::a;
   };
UncleBens
+1  A: 

This might help: http://www.parashift.com/c++-faq-lite/private-inheritance.html#faq-24.6

class Child : protected Parent
{
  public:
    using Parent::a;
}

Edit: added public.

Vlad
Nope! You forgot to put the using in the public section!
PierreBdR
Indeed :) Anyway, the correct answer is already given by UncleBens.
Vlad