我不明白为什么以下代码无法编译:
template< typename TypeArg >
class Data
{
public:
struct Selector1
{
};
template< typename Selector >
void foo()
{
}
};
template< typename TypeArg >
class Test
{
public:
void test();
};
template< typename TypeArg >
void Test< TypeArg >::test()
{
Data< TypeArg > data;
data.foo< typename Data< TypeArg >::Selector1 >();
}
我已经使用GCC 4.6和GCC 4.9对其进行了测试。两者都给我相同的错误:
test.cpp:在成员函数»void Test :: test()«:test.cpp:28:51:错误:预期»(«在»>«令牌test.cpp:28:53:错误:预期的主表达式在»)«之前
有人可以告诉我编译代码需要做什么吗?
由于的类型data
是从属的,因此的性质data.foo
未知,需要消除歧义:
data.template foo<typename Data< TypeArg >::Selector1>();
// ^^^^^^^^
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句