Compile error with templates - no matching function for call

前端 未结 2 1666
猫巷女王i
猫巷女王i 2021-02-15 16:01

I\'m trying to convert a string to a number. For that, I found the following way:

#include 
#include 

template 
         


        
相关标签:
2条回答
  • 2021-02-15 16:46

    Try

    int b = stringToNumber<int>(a);
    

    Because the template type T can not be deduced from any of the parameters (in this case std::string) you need to explicitly define it.

    0 讨论(0)
  • 2021-02-15 16:47

    You haven't supplied a template argument. Note that in C++11, you can use std::stoi:

    std::string a = "254";
    int b = std::stoi(a);
    
    0 讨论(0)
提交回复
热议问题