views:

339

answers:

1

I define a template function which loads a map from a CSV file:

template <class T>
bool loadCSV (QString filename, map<T,int> &mapping){
    // function here
}

I then try to use it:

map<int, int> bw;
loadCSV<int>((const QString)"mycsv.csv",&bw);

But get htis compile time error:

error: no matching function for call to 
‘loadCSV(const QString, std::map<int, int, std::less<int>, std::allocator<std::pair<const int, int> > >*)’

It seems my function call is bringing in some implicit arguments, but I don't understand the error and how to fix it. Any ideas?

+4  A: 

Drop the ampersand, you don't want to pass a pointer to the map (notice the asterisk at the end of the error message). Also, you don't have to explicitly cast the string literal. Moreover, the compiler should be able to deduce the template argument automatically.

loadCSV("mycsv.csv", bw);
avakar
ChrisInEdmonton
Good catch, it should definitely be a reference to const.
avakar
Thanks. Works now.
bugmenot77