5

我已经在 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);
}
4

1 回答 1

3

根据上面的评论:这似乎是 armcc 4.1 中的一个错误。

如果您的雇主与 ARM 签订了支持合同,您可以在此处向 ARM 提出支持问题:http ://www.arm.com/support/obtaining-support/index.php (单击“开发工具”选项卡,然后单击蓝色的“提出支持案例”按钮)。

至于解决方法,您可以尝试

  • 重新排列源文件中foo和的定义;bar和/或
  • foo在其定义之前和/或bar某处提供前向声明;和/或
  • foo<int>在声明之后添加某处的显式实例化,如下所示:

    template int foo(int arg);
    // or, if you like this style better,
    template int foo<int>(int arg);
    
于 2013-06-18T23:32:24.357 回答