Shachar Shemesh <[EMAIL PROTECTED]> writes:
> Oleg Goldshmidt wrote:
>
> >Oleg Goldshmidt <[EMAIL PROTECTED]> writes:
> >
> >
>
> >> I stand by my posting so far.
>
> >
> >Well, while it was making the round trip to the list and back, I also
> >made a trip to the bookshelf to check myself. Item 15 of Scott
> >Meyers's "Effective C++" confirms what I wrote: temps are const, and
> >for the reasons I covered. It explicitly says that with a declaration
> >like
> >
> > C& C::operator=(C& rhs) { ... }
> >
> >client code won't compile.
> >
> >
>
> Then you haven't understood my "dual existence" statement. Try out the
> following program:
>
> > #include <iostream>
> >
> > using namespace std;
> >
> > class a {
> > public:
> > void function() const {
> > cout<<"Const version called"<<endl;
> > }
> > void function() {
> > cout<<"Non-const version called"<<endl;
> > }
> > static void func2( const a & ) {
> > cout<<"Called with const reference"<<endl;
> > }
> > static void func2( a & ) {
> > cout<<"Called with non-const reference"<<endl;
> > }
> > };
> >
> > int main()
> > {
> > a().function();
> > a::func2(a());
> >
> > return 0;
> > }
>
> A temp is a non-const, but it cannot be bound to a non-const
> reference. I don't like it, but that seems to be the case.
I don't understand this statement. In "a().function()" your temp is
not const, according to your wishes. In "a::func2(a())" the
compiler-generated temp is const, as appropriate. If you don't believe
me, comment out the declaration of "void func2(const a&)" (you are
trying to call "void func2( a & )" if I understand your drift
correctly) and try to compile.
This is in complete agreement with what I wrote before (and what is
still quoted above).
> But the "Effective" series is fairly old. Older than the C++ ISO
> standard.
So? I seriously doubt this changed since.
> However, this is for cases where you don't want to change the right
> side. In my case, as explained, I do want to change the right side.
Thus changing the normal semantics of the assignment operator? This is
a shaky ground.
Hmm, this is getting OT here again. Care to post to
comp.lang.c++.moderated? You may get a much better reply from Scott
Meyers there ;-)
--
Oleg Goldshmidt | [EMAIL PROTECTED] | http://www.goldshmidt.org
=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]