3 回答

TA贡献1797条经验 获得超6个赞
你可以用static_cast<>()指定哪个f根据函数指针类型所隐含的函数签名使用:
// Uses the void f(char c); overload
std::for_each(s.begin(), s.end(), static_cast<void (*)(char)>(&f));
// Uses the void f(int i); overload
std::for_each(s.begin(), s.end(), static_cast<void (*)(int)>(&f));
或者,你也可以这样做:
// The compiler will figure out which f to use according to
// the function pointer declaration.
void (*fpc)(char) = &f;
std::for_each(s.begin(), s.end(), fpc); // Uses the void f(char c); overload
void (*fpi)(int) = &f;
std::for_each(s.begin(), s.end(), fpi); // Uses the void f(int i); overload
f
mem_fun
- 3 回答
- 0 关注
- 570 浏览
添加回答
举报