Given the following code:
template <typename T> struct Wrapper { T value; Wrapper(T val) : value(val) {} } int main() { Wrapper<int> x(42); int y = x;
Is there any way to implement the assignment
int y = x;
so that means y = x.value.
I know that overloading the assignment operator itself is impossible, since it is applied to the object on the left side of the assignment function and a friend with two arguments that are not allowed by the standard.
If this is not possible, by overloading any other statement or using some special tricks, how you implement it, with the exception of calling the get method provided by the Wrapper class, for example:
int y = x.get();
c ++ operator-overloading
Diggy
source share