题
我限定了从CSV文件加载一个地图模板函数:
template <class T>
bool loadCSV (QString filename, map<T,int> &mapping){
// function here
}
我然后尝试使用它:
map<int, int> bw;
loadCSV<int>((const QString)"mycsv.csv",&bw);
但得到htis编译时错误:
error: no matching function for call to
‘loadCSV(const QString, std::map<int, int, std::less<int>, std::allocator<std::pair<const int, int> > >*)’
看来我的函数调用带来一些隐含参数,但我不明白的错误,以及如何解决它。任何想法?
解决方案
挂断与字符,你不希望一个指针(在错误消息的结束通知的星号)传递到地图中。此外,您不必显式转换文字字符串。此外,编译器应能自动推断模板参数。
loadCSV("mycsv.csv", bw);
不隶属于 StackOverflow