Results 1 to 4 of 4

Thread: Overloading an operator to pass different variable

  1. #1
    Join Date
    Aug 2006
    Posts
    162

    Overloading an operator to pass different variable

    I'm working on C + + project but overloading operator << gives me an error (even copy and paste from the course): "error: expected constructor, destructor, or type conversion before &. Can any explain me the operator overloading in C++ with example.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Overloading an operator to pass different variable

    You can redefine or overload the function of most built-in operators in C++. Operating overloading allows you to pass different variable types to the same function and produce different results.For example, the compiler acts differently with regards to the subtraction operator “-“ depending on how the operator is being used.

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: Overloading an operator to pass different variable

    Code:
    # include <iostream>
    # include <header.h>
    
     int main ()
     (
        std:: court << "Hello world!" <<std:: endl;
        return 0;
     )

  4. #4
    Join Date
    May 2008
    Posts
    2,012

    Re: Overloading an operator to pass different variable

    Try this example for operator overloading :
    Code:
    Time operator+(const Time& lh, const Time& rh)
     {
       Time temp = lh;
       tmp.seconds += rh.seconds;
       if (tmp.seconds >= 60)
       {
         tmp.seconds -= 60;
         tmp.minutes++;
       }
       tmp.minutes += rhs.minutes;
       if (tmp.minutes >= 60)
       {
         tmp.minutes -= 60;
         tmp.hours++;
       }
       tmp.hours += rh.hours;
       return tmp;
     }

Similar Threads

  1. How to compare various overloading Operator
    By Plokstar in forum Software Development
    Replies: 4
    Last Post: 17-01-2011, 10:07 PM
  2. The way to operator overloading in Java
    By Kohlmann in forum Software Development
    Replies: 8
    Last Post: 18-09-2010, 09:57 PM
  3. Operator overloading in C sharp
    By Bottlenecked in forum Software Development
    Replies: 5
    Last Post: 23-01-2010, 09:52 AM
  4. Error in Operator Overloading
    By DutchDude in forum Software Development
    Replies: 2
    Last Post: 13-05-2009, 11:54 PM
  5. Overloading Assignment Operator and Copy constructor in C#
    By Japesh in forum Software Development
    Replies: 0
    Last Post: 14-01-2009, 03:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,007,458.10238 seconds with 17 queries