Re: operator function
From: Karl Heinz Buchegger (kbuchegg_at_gascad.at)
Date: 05/28/04
- Next message: Chris \( Val \): "Re: operator function"
- Previous message: Kenny: "Re: operator function"
- In reply to: Kenny: "Re: operator function"
- Next in thread: Chris \( Val \): "Re: operator function"
- Reply: Chris \( Val \): "Re: operator function"
- Reply: Kenny: "Re: operator function"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 28 May 2004 16:27:06 +0200
Kenny wrote:
>
> Its giving the same error:
> binary 'operator +' has too many parameters
> But I am passing only two parameters to be added
> why does it tell me this ?
>
Please don't top post. Put your reply beneath the text you
are replying to.
Seems I have fixed an error you have actually not seen right now :-)
This shows that it is always a good idea to tell us the exact error
message. Then we know what to look for.
> binary 'operator +' has too many parameters
Strange. There are a number of problems with your operator
(and with the GetTotalTime() function), but none
of them have anything to do with what the error message seems
to imply.
To remember, here is your operator
Setting operator+(const Setting &a, const Setting &b )
{
return a.GetTotalTime() + b.GetTotalTime() ;
}
When compiling this, my compiler emits:
error C2662: 'GetTotalTime' : cannot convert 'this' pointer from 'const class Setting' to 'class
Setting &'
Conversion loses qualifiers
Does that help you? Hint: A member function can be const. Under which circumstances
is that important?
When fixing this, the next error in the operator is:
error C2664: '__thiscall Setting::Setting(const class Setting &)' : cannot convert parameter 1 from
'int' to
'const class Setting &'
Reason: cannot convert from 'int' to 'const class Setting'
No constructor could take the source type, or constructor overload resolution was ambiguous
Hint: The compiler is talking about the result of the addition, which is an int. But the
operator returns a Setting object. In order to gap that bridge, the compiler needs to create
a Setting object from a single int, which requires a constructor that takes ...
-- Karl Heinz Buchegger kbuchegg@gascad.at
- Next message: Chris \( Val \): "Re: operator function"
- Previous message: Kenny: "Re: operator function"
- In reply to: Kenny: "Re: operator function"
- Next in thread: Chris \( Val \): "Re: operator function"
- Reply: Chris \( Val \): "Re: operator function"
- Reply: Kenny: "Re: operator function"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|