In this context, overloads cannot be resolved by the compiler. std::for_each() expects some arbitrary type F for its functor, and not some specific type of function, so the overloaded myFunc is ambiguous here.
You can explicitly choose which overload to use:
std::for_each( v.begin(), v.end(), (void (*)(int))myfunc); std::for_each( s.begin(), s.end(), (void (*)(std::string))myfunc);
Alternatives (last two of comments):
typedef void (*IntFunc)(int); std::for_each(, (IntFunc)myfunc); typedef void IntFunc(int); std::for_each(, static_cast<IntFunc*>(&myFunc));
source share