1
以下无法对其进行编译(在Linux的gcc 4.2.1,反正):在模板中使用从一个模板类类型定义(非成员)函数
template< typename T >
class Foo
{
public:
typedef int FooType;
};
void
ordinary()
{
Foo<int>::FooType bar = 0;
}
template< typename T >
void
templated()
{
Foo<T>::FooType bar = T(0);
}
int main(int argc, char **argv)
{
return 0;
}
问题是与这一行:
Foo<T>::FooType bar = 0;
...和编译器,使这种抱怨:
foo.c: In function ‘void templated()’:
foo.c:22: error: expected `;' before ‘bar’
通常人们看到这个当类型尚未ð呃,但据我所知,Foo < T> :: FooType在模板化()内应该是完全有效的。
就是这样!非常感谢。 – atomicpirate 2010-03-10 16:41:14