【发布时间】:2011-02-01 17:28:25
【问题描述】:
我正在尝试使用嵌套类的完全限定名称,如下所示,但编译器正在犹豫!
template <class T> class Apple {
//constructors, members, whatevers, etc...
public:
class Banana {
public:
Banana() {
//etc...
}
//other constructors, members, etc...
};
};
template <class K> class Carrot{
public:
//etc...
void problemFunction()
{
Apple<int>::Banana freshBanana = someVar.returnsABanana(); //line 85
giveMonkey(freshBanana); //line 86
}
};
我的问题是,编译器说:
Carrot.h:85: error: expected ';' before 'freshBanana'
Carrot.h:86: error: 'freshBanana' was not declared in this scope
我曾认为使用完全限定名称允许我访问这个嵌套类?它可能会打我的脸,但我到底在这里看不到什么??
【问题讨论】:
-
我注意到使用旧版本 gcc(我使用 gcc-3.4)的嵌套类的编译问题; gcc-4.x 没有这样的问题,而且这段代码编译得很好(经过小的返工)
标签: c++ templates gcc nested-class