Article View: comp.sys.mac.programmer.codewarrior
Article #1438Re: CWP6: illegal implicit conversion...
From: meeroh
Date: Fri, 22 Sep 2000 06:36
Date: Fri, 22 Sep 2000 06:36
49 lines
2355 bytes
2355 bytes
In article <39CAF8B8.8A567B6C@optonline.net>, ronw@optonline.net wrote:
>Hmm... It looks like I spoke too soon. Here's a bit of code that compiles
>just fine in CWPro 5.3. Did something
>all of a sudden change in CW6?
That's exactly what I tried to explain in the previous post. Here's your
problem:
If you have
class Foo () {
public:
Foo (int);
};
int Fun (Foo& whatever);
Then writing:
Fun (Foo (2));
is exactly the same as writing
const Foo __temporary (2);
Fun (__temporary);
And if you look at the second line of that you see the problem: Fun
takes a Foo&, but you are passing it a const Foo&. You can't do that,
and for a good reason: const Foo is a FOo you can't modify. However,
declaring the function with Foo& means that it can modify the argument.
Those two notions are not compatible -- __temporary can't be modified,
but Fun wants the ability to modify its argument.
You need to declare Fun to take const Foo&, or you need to explicitly
instantiate the temporary with
Foo __temp (2);
Fun (__temp);
and in that case you have to understand that you are discarding any
changes to __temp made by Fun.
Hth,
meeroh
--
To get random signatures put text files into a folder called "Random Signatures" into your Preferences folder.
Technical Details
Message-ID:
<macdev-42A394.02363922092000@news.mit.edu>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!sn-east!supernews.com!news-feed.riddles.org.uk!arclight.uoregon.edu!newsfeed.mathworks.com!bloom-beacon.mit.edu!senator-bedfellow.mit.edu!dreaderd!not-for-mailReferences:
<39CA60B0.DC1700A2@mindspring.com> <39CA6ACD.31F060CF@mindspring.com> <macdev-649CBD.23265021092000@news.mit.edu> <39CAF8B8.8A567B6C@optonline.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10bcce,4a0d644260b480cb X-Google-Attributes: gid10bcce,public X-Google-Thread: f635e,4a0d644260b480cb X-Google-Attributes: gidf635e,public X-Google-ArrivalTime: 2000-09-21 23:45:02 PST Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-02!sn-east!supernews.com!news-feed.riddles.org.uk!arclight.uoregon.edu!newsfeed.mathworks.com!bloom-beacon.mit.edu!senator-bedfellow.mit.edu!dreaderd!not-for-mail From: meeroh <macdev@meeroh.org> Newsgroups: comp.sys.mac.programmer.codewarrior,codewarrior.mac Mail-Copies-To: poster Subject: Re: CWP6: illegal implicit conversion... Organization: MIT References: <39CA60B0.DC1700A2@mindspring.com> <39CA6ACD.31F060CF@mindspring.com> <macdev-649CBD.23265021092000@news.mit.edu> <39CAF8B8.8A567B6C@optonline.net> User-Agent: MT-NewsWatcher/3.0 (PPC) Date: Fri, 22 Sep 2000 02:36:39 -0400 Message-ID: <macdev-42A394.02363922092000@news.mit.edu> Lines: 49 NNTP-Posting-Host: ALUMINUM-27.MIT.EDU X-Trace: dreaderd 969604600 9425 18.101.0.199