首页 新闻 会员 周边

c++ template类中嵌套类问题

0
悬赏园豆:10 [已解决问题] 解决于 2010-03-06 13:38

#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
Aldrich的主页 Aldrich | 初学一级 | 园豆:170
提问于:2010-03-04 14:56
< >
分享
最佳答案
0

见此:

http://blog.codingnow.com/2010/01/cpp_template.html

及此:

http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/Name-lookup.html#Name-lookup

收获园豆:10
Kabie | 菜鸟二级 |园豆:235 | 2010-03-04 19:19
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册