Re: operator function
From: Kenny (lerameur_at_yah00.c0m)
Date: 05/28/04
- Next message: Kenny: "Re: operator function"
- Previous message: Chris \( Val \): "Re: operator function"
- In reply to: Karl Heinz Buchegger: "Re: operator function"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 28 May 2004 10:47:58 -0400
"Karl Heinz Buchegger" <kbuchegg@gascad.at> wrote in message
news:40B74C3A.E55B4D36@gascad.at...
> 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?
Well I guess you are talking about a copy constructor right?
>
> 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 ...
well this part I can solve by making the function void and just print out
the value so it will not return anything.
cout<< a.GetTotalTime() + b.GetTotalTime();
>
> --
> Karl Heinz Buchegger
> kbuchegg@gascad.at
- Next message: Kenny: "Re: operator function"
- Previous message: Chris \( Val \): "Re: operator function"
- In reply to: Karl Heinz Buchegger: "Re: operator function"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|