我有一个继承struct A : public B
,我想对B隐藏个别函数,这可能吗?
我知道在 A 声明中使用 using BMethod
可以实现相反的效果。
干杯
最佳答案
如果您想有选择地对 B 隐藏函数,那么首先使用公共(public)继承没有多大意义。
使用私有(private)继承并有选择地将 B 中的方法带入 A 的范围:
struct B{
void method1(){};
void method2(){};
};
struct A : private B{
using B::method1;
};
A a;
a.method1();
a.method2(); //error method2 is not accesible
关于c++ - c++中隐藏特定函数的一种方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4908539/