Sunday, 8 September 2013

overloading a binary operator

Tags

While overloading a binary operator can we provide default values?
Ans: No!. This is because even if we provide the default arguments to the parameters of the overloaded operator function we would end up using the binary operator incorrectly. This is explained  in the following example: 


                     sample operator + ( sample a, sample b = sample (2, 3.5f ) )
                             {
                             }

                             void main( )
                             {
                                    sample s1, s2, s3 ;
                                    s3 = s1 + ; // error
                             }



EmoticonEmoticon