开发者

How to skip a class with public access to a function?

I have this setup:

class A
{
  public:
  virtual void Function();
}

class B : private A
{

}

class C : public B
{
public:
// I want to expo开发者_Go百科se A::Function() here
}

I tried to do this by adding:

class C : public B
{
public:
  virtual void Function();
}

and

C::Function()
{
  A::Function();
}

but I get and "inaccessible base" error.

Is it possible to do something like this?


In B you can change the accessibility of A::Function to protected:

class B : private A
{
protected:
    using A::Function;
};

In C::Function (and elsewhere in C) you will then have to refer to the function as B::Function, not A::Function. You could also public: using B::Function; in C instead of implementing a C::Function that just calls B::Function.


You can't do this. The fact that B inherits from A is an implementation detail and you are not allowed to access it from C- just like you can't access B's private functions or member variables.

This would be completely legal if B inherited protected or public from A.


If you can change it to class B : protected A it should work.


Not really. The scenario you're describing would indicate that your class hierarchy needs to be reworked.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜