Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualCosmic314

Posted 02 October 2013 - 11:35 AM

I create a type:

typedef std::map<std::string,std::string> StringMap;

Later I create a function template declared as:

template<typename K, typename V>
void function_name(std::map<K,V> *map_object);

I go to use the function_name as so:

function_name<StringMap>(&some_map_object);

The compiler complains with:

error:  no matching function for call to 'function_name(StringMap*)'

When I supply both types to the template arguments (std::string,std::string) in this case, everything is fine.  I would have thought that the compiler might be able to infer that StringMap = std::string,std::string but it looks like I'm wrong.  

 

Is this mainly because the compiler cannot mismatch on number of type arguments supplied in a template?


#1Cosmic314

Posted 02 October 2013 - 11:34 AM

I create a type:

typedef std::map<std::string,std::string> StringMap;

Later I create a function template declared as:

template<typename K, typename V>
void function_name(std::map<K,V> *map_object);

I go to use the function_name as so:

function_name<StringMap>(&some_map_object);

The compiler complains with:

error:  no matching function for call to 'function_name(StringMap*)'

When I supply both types to the template arguments (std::string,std::string) in this case, everything is fine.  I would have thought that the compiler might be able to infer that StringMap = std::string,std::string but it looks like I'm wrong.  

 

Is this mainly because the compiler cannot mismatch on number of type arguments supplied in a template?


PARTNERS