有没有任何简单的方法来暴露私人父类c ++的方法 [英] is there any easy way to expose methods of private parent class c++

查看:176
本文介绍了有没有任何简单的方法来暴露私人父类c ++的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法直接暴露私人父类的一些方法。
在下面的示例中,如果我有一个类型Child的对象,我想能够直接调用其父的方法a(),而不是b();
当前解决方案产生大量样板代码,特别是如果有很多参数。

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);
            }
   };


推荐答案

可以使用using声明。

You can use the using declaration.

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

这篇关于有没有任何简单的方法来暴露私人父类c ++的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆