混淆的标题,希望代码能够澄清:
令人困惑的标题,希望通过代码来澄清:
struct MyNestedType {
void func();
};
struct MyType {
MyNestedType* nested;
}
std::vector<MyType> vec;
// ... populate vec
// I want something approximating this line, but that doesn't use made-up C++!
std::for_each(vec.begin(), vec.end(), std::mem_fun_ref(&MyType::nested->func));
我希望对一个容器中的每个元素都调用一个方法,但是该方法并非类型本身的方法,而是该类型中包含的某种方法... 我知道我可以编写函数对象来"传递"调用,但有几种方法我想要调用,那样会很混乱。
有什么好的想法吗?