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)
究竟什么是难以接近的,为什么?
试试A< ::B>或A<struct B>.
在里面C,不合格的引用B会拾取所谓的inject-class-name,它是通过基类引入的A.由于A私有地继承B,所以注入类名跟随并且也将是私有的,因此是不可访问的C.
另一天,另一种语言怪癖......
| 归档时间: |
|
| 查看次数: |
274 次 |
| 最近记录: |