|
|
![]() |
| Thread Tools | Search this Thread |
#1
| |||
| |||
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 |
#2
| |||
| |||
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); I think you wanted to do: Code: time1 = time2 + hours + minutes + seconds |
#3
| |||
| |||
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. |
![]() |
|
Tags: c program, error, operator overloading |
Thread Tools | Search this Thread |
|
![]() | ||||
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 |