overloading unary operators in cpp 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);
};
};