How can you create a new operator through operator overloading?

Answer:
You cannot create a new operator through operator overloading. You can only redefine an existing operator, with certain limitations. As an example, for a class of complex numbers, having a real and an imaginary part, you might want an addition operator. This is the skeleton of code to do that. I only show the operator, not any constructors or other operators or methods, etc.

class complex {
private:
double real, imaginary;
public:
complex operator+ (complex operand) {
complex temp;
temp.real = this.real + operand.real;
temp.imaginary = this.imaginary + operand.imaginary;
return temp;
}
};





The above answer is for C++. Since this question is also categorized in Java Programming it's important to note that operator overloading is not currently possible in Java.
First answer by Alex146. Last edit by Alex146. Contributor trust: 419 [recommend contributor recommended]. Question popularity: 1 [recommend question].