'Object reading and writing overload in C++

I know that the assignment operator can be overloaded. When writing to an object, the object's overload function is called.

Obj = 10; // Obj's assignment overload function called.

Is there a way to define a function to be called when an object is read?

int a = Obj;

In this case Obj's reading function would be called and the return value would be assigned to a.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source