oops

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sasidharan091
    New Member
    • Aug 2009
    • 6

    oops

    concepts of overloding operators with an example
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Use the Internet to research this.

    The idea is to make yout code easy to use. If you have x + 10 and x is an int then 10 is added to the int value. If x is a date, then 10 days would be added to the date value.

    Unfortunately, the + does not work with dates. So, the overload is your implementation of the + operator for use with date variables.

    Truly, the Internet has a ton of info on this.

    Comment

    • manjuks
      New Member
      • Dec 2007
      • 72

      #3
      Hi,

      Assume that you wants to add two strings (concatenate) say S1 and S2 like below

      S = S1 + S2

      But its not possible since + doesn't add strings, So you need to overload + operator to add (concatenate) the strings.

      This is just an example to understand when you need to overload operators.

      Thanks,
      Manjunath

      Comment

      Working...