overloading unary operator in c++ code example
Example: unary overload operator cpp
class A {
public:
int value;
A(int v1) : value(v1) {};
// overloaded minus (-) operator
A operator- () {
return A(-value);
};
};
class A {
public:
int value;
A(int v1) : value(v1) {};
// overloaded minus (-) operator
A operator- () {
return A(-value);
};
};