When this code is compiled:
Code:
#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;
}
It will produce an error like this:
error: must use ‘.*’ or ‘->*’ to call pointer-to-member function in ‘method (...)’
for the code:
What is needed to get this program to work correctly?
Bookmarks