Operator overloading in OOP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Qasimtn
    New Member
    • Nov 2006
    • 4

    Operator overloading in OOP

    In Operator Overloading just suppose i am talking about operator(+),
    if i have a class Bluejem and i want to add three object (Cascaded Operation)

    Code:
    class Bluejem
    {
    ........
    //member function
    Bluejem operator+(Bluejem& obj );
    .......
    };
    
    void main()
    {
            blue_return=blue_1+blue_2+blue_3;
    
    .........
    .........
    }
    i am confused in knowing that which two objects will add first
    blue_2+blue_3
    or
    blue_1+blue_2
    help me!
    on saturday i have to submit my lab work on operator overloading.... .
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    Originally posted by Qasimtn
    In Operator Overloading just suppose i am talking about operator(+),
    if i have a class Bluejem and i want to add three object (Cascaded Operation)

    Code:
    class Bluejem
    {
    ........
    //member function
    Bluejem operator+(Bluejem& obj );
    .......
    };
    
    void main()
    {
            blue_return=blue_1+blue_2+blue_3;
    
    .........
    .........
    }
    i am confused in knowing that which two objects will add first
    blue_2+blue_3
    or
    blue_1+blue_2
    help me!
    on saturday i have to submit my lab work on operator overloading.... .
    Associativity determines how operators of the same precedence are grouped. The associativity of + is left to right, so in
    blue_return=blu e_1+blue_2+blue _3;
    the subexpression blue_1+blue_2 would be evaluated first, i.e.
    blue_return=(bl ue_1+blue_2)+bl ue_3;

    Comment

    Working...