Overloaded operands and function definitions Question
Jamie Andold (2)
Jan 22, 2013 at 3:03am UTC
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?
yamex5 (17)
Jan 22, 2013 at 4:07am UTC
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.
Santosh Reddy (58)
Jan 22, 2013 at 11:36am UTC
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 UTC
vlad from moscow (3662)
Jan 22, 2013 at 5:53pm UTC
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() ); }
};