C++: bizarre occurrence of “Request for member X of Y which is of non-class type Z”
问题 The following program, compiled with g++ 4.6, yields the error request for member ‘y’ in ‘a2’, which is of non-class type ‘A<B>(B)’ at its last line: #include <iostream> template <class T> class A { public: T y; A(T x):y(x){} }; class B { public: int u; B(int v):u(v){} }; int main() { int v = 10; B b1(v); //works A<B> a1(b1); //does not work (the error is when a2 is used) A<B> a2(B(v)); //works //A<B> a2((B(v))); std::cout << a1.y.u << " " << a2.y.u << std::endl; } As can be seen from the