【发布时间】:2013-04-29 23:34:45
【问题描述】:
我已经在 VS10 和 armcc4.1 [Build 561] 上测试了以下代码的编译。函数 depth1() 和 depth2() 都在 VS 上编译,但是 armcc 只会编译 depth1(),同时为 depth2() 给出错误 304(没有匹配参数列表的实例)。当 foo 和 bar 为非静态时,它在 armcc 上也能正常编译。
我很乐意了解原因。
template <class T>
static T foo(T arg)
{
return arg*5;
}
template <class T>
static T bar(T arg)
{
return foo<T>(arg);
}
void depth2()
{
int i = 12;
i = bar<int>(i);
}
void depth1()
{
int i = 12;
i = foo<int>(i);
}
【问题讨论】:
-
看起来像一个编译器错误。 arm-eabi-gcc 也可以正常工作。可能与 foo
在尝试编译 bar 之前不存在有关 -
谢谢@Andres。从错误消息来看,似乎是这种情况;但是不清楚为什么
bar编译而foo不编译。可能与所需模板的深度有关。 -
尝试先定义 depth1(),然后定义 depth2(),或者提供 foo
的显式实例化。是的,这是一个编译器错误,我在这里提供了可能的解决方法。 -
知道如何报告这样的错误吗?
标签: c++ templates compiler-errors