1. ## Two + operators

Okay, I'm writing a class, and I want to know how I can have two different + operators in the class.

Is it even possible to do this?

Thanks!

2. Yes, for different types of right-hand side arguments.

3. So as long as they have different parameters, you can do it?

4. Isn't there also a uranary + operator analgalous to the uranary - operator? I could be very wrong about this...

5. ++ and -- you mean?

6. "unary"

You mean a '+5' analogous to '-5' (for example)?

7. Yeah, Zach knows what I'm thinking. Is that possible?

8. Yep.

Code:
```class A
{
public:
A operator+(); // Unary +: A x; +x;
A operator+(A b); // Binary +: A x, y; x + y;
};```

9. *fist pump*
And I suppose other things would go on this line...

10. Originally posted by Zach L.
Yep.

Code:
```class A
{
public:
A operator+(); // Unary +: A x; +x;
A operator+(A b); // Binary +: A x, y; x + y;
};```
Not that I don't have confidence in you, Zach, but I was almost sure that you were wrong. Then I checked and learned.

Why is there a unary + operator? With the basic types, +x returns x. So why use +x at all?

11. +x = x if x is a number, however, c++ provides a way to overload + so you can use it to do whatever you want for your class, one of the features that I like in c++.

12. Originally posted by pianorain
Not that I don't have confidence in you, Zach, but I was almost sure that you were wrong. Then I checked and learned.
Thats good. Someone keeping me honest.

Why is there a unary + operator? With the basic types, +x returns x. So why use +x at all?
I really can't see much use for it. If you're gonna use operators, they should logically work as you'd expect them (otherwise, use a named function), and I can't think of any logical place where +x != x. It was probably added to C++ since it is mathematically valid syntax.