Quick Question about Operator Overloading

Hello,

When operator overloading, are all parameters in each operator (operator+, operator-, etc) pre-defined?

~Flurite
...predefined as in there's a limit on the types of the arguments they can take, or as in something else?

-Albatross
The types and the number of arguments.
I'm not sure what you mean by pre-defined.

I believe the only things that are predefined are
a) The number of arguments each operator takes (+ - * / = % all take 2, ++ -- take 1, ?: takes 3)
b) The behavior with the basic types are defined (int + int, double + int, etc.)

Here's a good reference regarding how to overload each operator:
http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B
Last edited on
@Stewbond,

Thanks. I am assuming the type is pre-defined then as well, from what you say in b?
What I'm saying in b is that you don't have to define behavior for int + int. It's already done. But if you have your own class, then you will need to do it yourself.
Not at all! What Stewbond was saying is that the operators are all already defined for all the basic types and for operations using only basic types.

If something more complex like a class is involved you're free to specify your own types.

EDIT: Neenjah.

-Albatross
Last edited on
Ahh, I see.

Answer: Overloading operators for classes allows you to specify the types of the parameters, but the number of parameters is set.

That right?
Pretty much.

-Albatross
Topic archived. No new replies allowed.