开发者

is there any easy way to expose methods of private parent class c++

开发者 https://www.devze.com 2022-12-21 17:40 出处:网络
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 no

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 so开发者_JAVA技巧lution 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);
            }
   };


You can use the using declaration.

class Child : private Parent {
    public:
        using Parent::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.

0

精彩评论

暂无评论...
验证码 换一张
取 消