Thread: operator overloading

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    39

    Cool operator overloading

    well,if i want to add two objects of a same class e.g. fraction1+fraction2 and have developed the function for +.then should i simply do this
    fraction1+fraction2;
    which should call the overloaded operator function?

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    Yup. Exactly how it gets done depends on how you implement it. Often the object on the left hand side of the operator is implemented as the calling object and the object on the right hand side is the parameter passed to the operator.

    Now consider what you need to do if the you have an instance of type int or type double on one side or the other of the addition operator? The version you implemented only covers the case where both the lhs and rhs objects are of the user defined class. Let the fun begin.

Popular pages Recent additions subscribe to a feed