涉及私有继承的C++编译器错误

HC4*_*ica 6 c++ inheritance templates compiler-errors private-inheritance

有人可以向我解释以下编译器错误:

struct B
{
};

template <typename T>
struct A : private T
{
};

struct C : public A<B>            
{                                                                             
    C(A<B>);   // ERROR HERE
};
Run Code Online (Sandbox Code Playgroud)

指示行的错误是:

test.cpp:2:1: error: 'struct B B::B' is inaccessible
test.cpp:12:7: error: within this context
Run Code Online (Sandbox Code Playgroud)

究竟什么是难以接近的,为什么?

Xeo*_*Xeo 6

试试A< ::B>A<struct B>.

在里面C,不合格的引用B会拾取所谓的inject-class-name,它是通过基类引入的A.由于A私有地继承B,所以注入类名跟随并且也将是私有的,因此是不可访问的C.

另一天,另一种语言怪癖......

  • 我还打开了一个[后续问题](http://stackoverflow.com/q/9223441/500104). (2认同)