我一直在尝试使用clang编译一个项目(使用gcc/g++没有问题),但编译卡在了模板调用上。 我尝试创建了一个最简单的类似代码来展示相同的错误信息。以下是代码:
#include <vector>
#include <utility>
#include <iostream>
using namespace std;
int A( double in )
{
return 1;
}
int A( int in )
{
return 1;
}
template<class M, class T>
M test(T input, M (fun) (T) )
{
return fun( input );
}
int main( int argc, const char *argv[] )
{
cout << test( (int) 1, A ) << test( (double) 1.2, A ) << endl;
return 0;
}
clang的错误(当然会出现两次):
error: no matching function for call to 'test'
candidate template ignored: couldn't infer template argument 'M'
gcc没有抱怨。
请注意,M是返回值类型,始终为“int”。
有人知道哪个是正确的以及为什么吗?
谢谢。
*
显式地解引用函数指针来调用它。)虽然如果你真的想的话可以这样做,但是这并没有什么区别。 - BoBTFish