Overloaded operands and function definitions Question

Jan 22, 2013 at 3:03am
Is it possible to write two or more function definitions for the + operator and place them both is a struct definition? Why or why not?
Jan 22, 2013 at 4:07am
My understanding is that if you are going to add two different types together, you will need to define to overloaded operator members to handle the two different ways the parameters can be added.
Jan 22, 2013 at 11:36am
Yes, you can have any number of overloaded + operators as long as all the function parameters are different. (unique signature)
Last edited on Jan 22, 2013 at 11:37am
Jan 22, 2013 at 5:53pm
Consider the example

1
2
3
4
5
struct A
{
   const A operator +( const A & ) { return ( A() ); }
   const A operator +( const A & ) const { return ( A() ); }
};
Topic archived. No new replies allowed.