I would like to use an std::function as an argument of a method and set its default value as std::stoi.
I tried the following code:
void test(std::function<int(const std::string& str, size_t *pos , int base)> inFunc=std::stoi)
Unfortunately I get the following error:
no viable conversion from '<overloaded function type>' to 'std::function<int (const std::string &, size_t *, int)>'
I managed to compile by adding creating a dedicated method.
#include <functional>
#include <string>
int my_stoi(const std::string& s)
{
return std::stoi(s);
}
void test(std::function<int(const std::string&)> inFunc=my_stoi);
What's wrong in the first version?
Isn't it possible to use std::stoi as default value?