Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 13-05-2009
Member
 
Join Date: Apr 2009
Posts: 22
Error in Operator Overloading

This program is supposed to receive numbers (hours minutes seconds) that will add an object time. But when compiling the compiler tells me: error: `Time Time:: operator + (long int, long int, long int) 'must take either zero or one argument.
The error is at line 9 of time.hpp.
Code:
# define time
 
 time class 
  ( 
      public: 

      Duration (a_hours int = 0, int a_minutes = 0, int a_seconds = 0); 
      Time operator + (long hours, long minutes, long seconds); 
      Time operator + (const Time & duration); 
      void display (); 

      private: 

      int m_hours; 
      int m_minutes; 
      int m_seconds; 
  ); 

  # endif
Reply With Quote
  #2  
Old 13-05-2009
Member
 
Join Date: May 2008
Posts: 2,008
Re: Error in Operator Overloading

First mention of integer in the error message that is long shortcut to long integer. it is what is marked in the message (long int).

Code:
  Time operator + (long hours, long minutes, long seconds);
Then, the error message is quite clear there should be one or zero arguments to overload the + operator.
I think you wanted to do:

Code:
  time1 = time2 + hours + minutes + seconds
Reply With Quote
  #3  
Old 13-05-2009
Member
 
Join Date: May 2008
Posts: 2,383
Re: Error in Operator Overloading

Translation of the error:
Service Time Time:: operator + (long int, long int, long int) should take one or no argument.In other words you can not overload a operator giving more than one parameter, it does not make sense elsewhere. And this is not overloaded. When you want to add directly with just 3 values that you call the constructor like this time (N1, N2, N3), and your second operator + will be called.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Error in Operator Overloading"
Thread Thread Starter Forum Replies Last Post
How to compare various overloading Operator Plokstar Software Development 4 17-01-2011 10:07 PM
what is the difference between unary and binary operator overloading in C #? Asis Software Development 4 27-12-2010 06:32 AM
The way to operator overloading in Java Kohlmann Software Development 8 18-09-2010 09:57 PM
Operator overloading in C sharp Bottlenecked Software Development 5 23-01-2010 09:52 AM
Overloading an operator to pass different variable Flaco Software Development 3 25-12-2009 11:27 AM


All times are GMT +5.5. The time now is 12:29 AM.