Follow-up question to this one.
Basically, in the following code, why does the compiler think that the B
inside A<B>
in C
s constructor refer to the (inaccessible) constructor of the B
base class?
struct B{};
template <typename T>
struct A : private T{};
struct C : public A<B>{
C(A<B>); // ERROR HERE
};
Live example on Ideone. Output:
prog.cpp:1:9: error: 'struct B B::B' is inaccessible
prog.cpp:7:7: error: within this context
Note that the same error pops up if you change the constructor argument to A<B*>
, A<B&>
or even A<const B>
. Also note that three of MSVC10, GCC 4.7 and Clang 3.1 ToT will error out, so it must be something in the C++ spec. What is it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…