As with many other adaptors, it is usually inconvenient to use
struct B {
virtual void print() = 0;
};
struct D1 : public B {
void print() { cout << 'I'm a D1' << endl; }
};
struct D2 : public B {
void print() { cout << 'I'm a D2' << endl; }
};
int main() {
vector<B*> V;
V.push_back(new D1);
V.push_back(new D2);
V.push_back(new D2);
V.push_back(new D1);
for_each(V.begin(), V.end(), mem_fun(&B::print));
}
Defined in the standard header functional, and in the nonstandard backward-compatibility header function.h.
Parameter | Description |
---|---|
Result | The member function's return type. |
X | The class whose member function the |
Adaptable Unary Function
unary_function<X*, Result>
Member | Where defined | Description |
---|---|---|
argument_type | Adaptable Unary Function | The type of the argument: |
result_type | Adaptable Unary Function | The type of the result: |
Result operator()(X* x) const | Unary Function Function | call operator. Invokes |
explicit mem_fun_t(Result (X::*f)()) | mem_fun_t | See below. |
template <class Result, class X> mem_fun_t<Result, X> mem_fun(Result (X::*f) ()); | mem_fun_t | See below. |
These members are not defined in the Adaptable Unary Function requirements, but are specific to
Member | Description |
---|---|
explicit mem_fun_t(Result (X::*f)()) |