代码
#include
<
stdio.h
>
template < class T >
class C
{
public :
struct A
{
T x;
};
struct B: A
{
int y;
B() {
x = 10 ; // error
}
};
};
int main( void )
{
C < int > ::B b;
b.x = 5 ; // right
b.y = 6 ;
return 0 ;
}
template < class T >
class C
{
public :
struct A
{
T x;
};
struct B: A
{
int y;
B() {
x = 10 ; // error
}
};
};
int main( void )
{
C < int > ::B b;
b.x = 5 ; // right
b.y = 6 ;
return 0 ;
}
编译以上代码会报如下错误:
test.cpp: In constructor `C<T>::B::B()':
test.cpp:16: error: `x' was not declared in this scope
哪位朋友可以给出一个有说服力的解释?