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
.
精彩评论