求高手解决这个C++问题

 

代码
#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;
}
 

 

 

编译以上代码会报如下错误:

test.cpp: In constructor `C<T>::B::B()':
test.cpp:16: error: `x' was not declared in this scope

哪位朋友可以给出一个有说服力的解释?

posted @ 2010-03-04 11:43  Aldrich  阅读(295)  评论(1编辑  收藏  举报