123456789101112131415161718192021222324252627282930313233
#include <iostream> using std::ostream; class Value { public: explicit Value(int amount) : m_amount(amount) {} void Increment() { ++m_amount; } void WriteTo(ostream& stream) const { stream << m_amount; } private: int m_amount; }; ostream& operator << (ostream& stream, const Value& value) { value.WriteTo(stream); return stream; } int main() { typedef void (Value::*ValueMethod)(void); Value value(41); ValueMethod method = &Value::Increment; value.*method(); std::cout << "The value is " << value << std::endl; return 0; }
value.*method();
(value.*method)();