Thread View: comp.sys.mac.programmer.codewarrior
9 messages
9 total messages
Started by Gordon Tillman
Thu, 21 Sep 2000 00:00
CWP6: illegal implicit conversion...
Author: Gordon Tillman
Date: Thu, 21 Sep 2000 00:00
Date: Thu, 21 Sep 2000 00:00
21 lines
1292 bytes
1292 bytes
Howdy All,
I was recompiling my CPLAT sources (from Ken Stahlman) under CWP6 and
encountered several places in the code where I am now receiving this
error. (Don't worry about what a CP_Region is...suffice it to say its a
valid thing)s:
Error: illegal implicit conversion from 'CP_Region' to 'CP_Region &'
Here is the snippet of code that causes the error:
OnDraw( CP_Region(fPlatformWindow->visRgn) );
Now, if I change the code to read like this:
CP_Region cpr(fPlatformWindow->visRgn);
OnDraw( cpr);
Then it compiles fine. I wonder why this is so???
--gordon
Re: CWP6: illegal implicit conversion...
Author: meeroh
Date: Thu, 21 Sep 2000 00:00
Date: Thu, 21 Sep 2000 00:00
35 lines
1736 bytes
1736 bytes
In article <39CA60B0.DC1700A2@mindspring.com>, got@mindspring.com wrote: >Howdy All, > >I was recompiling my CPLAT sources (from Ken Stahlman) under CWP6 and >encountered several places in the code where I am now receiving this >error. (Don't worry about what a CP_Region is...suffice it to say its a >valid thing)s: > > Error: illegal implicit conversion from 'CP_Region' to 'CP_Region &' > >Here is the snippet of code that causes the error: > > OnDraw( CP_Region(fPlatformWindow->visRgn) ); > >Now, if I change the code to read like this: > > CP_Region cpr(fPlatformWindow->visRgn); > OnDraw( cpr); > >Then it compiles fine. I wonder why this is so??? In the first case the CP_Region is a temporary, and is therefore a const. In the second case it's not. If you declared the second one as const CP_Region you'd get the same error. You should probably change OnDraw to take a const CP_Region&, if it doesn't modify the region. Hth, meeroh -- To get random signatures put text files into a folder called "Random Signatures" into your Preferences folder.
Re: CWP6: illegal implicit conversion...
Author: Ronald Webster
Date: Thu, 21 Sep 2000 00:00
Date: Thu, 21 Sep 2000 00:00
56 lines
2357 bytes
2357 bytes
Looks to me like OnDraw wants a reference to an object, which is a veiled
way of sending the address of the object, rather than the value of the
object, to the function.
In order to have this, you must have the object itself, i.e. an instance of
the class CP_Region.
In your second example, you have an instance: cpr.
In your first example, you don't. All you have is the value.
Try this:
int Myfuncref(int& x)
{
return(x);
}
int Myfuncval(int x)
{
return(x);
}
Then in main()...
q=Myfuncref(2); // This line generates an error.
q=Myfuncval(2);
You'll get a compiler error. The reason is that you can't take the address
of 2. Same problem you're having. If you want to call by reference, you
have to have an object, not just the value it leaves behind.
Good luck.
-Ron Webster
Gordon Tillman wrote:
> Howdy All,
>
> I was recompiling my CPLAT sources (from Ken Stahlman) under CWP6 and
> encountered several places in the code where I am now receiving this
> error. (Don't worry about what a CP_Region is...suffice it to say its a
> valid thing)s:
>
> Error: illegal implicit conversion from 'CP_Region' to 'CP_Region &'
>
> Here is the snippet of code that causes the error:
>
> OnDraw( CP_Region(fPlatformWindow->visRgn) );
>
> Now, if I change the code to read like this:
>
> CP_Region cpr(fPlatformWindow->visRgn);
> OnDraw( cpr);
>
> Then it compiles fine. I wonder why this is so???
>
> --gordon
Re: CWP6: illegal implicit conversion...
Author: Gordon Tillman
Date: Thu, 21 Sep 2000 00:00
Date: Thu, 21 Sep 2000 00:00
26 lines
1427 bytes
1427 bytes
Hello Again! First of all...thanks meeroh and Ronald for the updates. For some reason I thought that doing this... > OnDraw( CP_Region(fPlatformWindow->visRgn) ); ...was still supplying an instance of CP_Region (like an anonymous one or something!) Hey, I appreciate the info! Between the great folks at MW and you regulars, the CW newsgroups have some of the highest signal-to-noise ratios [that's a good thing :-) ] of *any* newsgroup I have ever participated in. --gordon > > Now, if I change the code to read like this: > > CP_Region cpr(fPlatformWindow->visRgn); > OnDraw( cpr); > > Then it compiles fine. I wonder why this is so??? > > --gordon
Re: CWP6: illegal implicit conversion...
Author: meeroh
Date: Thu, 21 Sep 2000 00:00
Date: Thu, 21 Sep 2000 00:00
20 lines
1302 bytes
1302 bytes
In article <39CA6ACD.31F060CF@mindspring.com>, got@mindspring.com wrote: >Hello Again! > >First of all...thanks meeroh and Ronald for the updates. For some >reason I thought that doing this... > >> OnDraw( CP_Region(fPlatformWindow->visRgn) ); > >...was still supplying an instance of CP_Region (like an anonymous one >or something!) It does, and that instance is always non-modifiable, i.e. const. Therefore, it can't be passed to a function that would modify it. That's all there is :-) meeroh -- To get random signatures put text files into a folder called "Random Signatures" into your Preferences folder.
Re: CWP6: illegal implicit conversion...
Author: Howard Hinnant
Date: Fri, 22 Sep 2000 00:00
Date: Fri, 22 Sep 2000 00:00
41 lines
2050 bytes
2050 bytes
In article <macdev-42A394.02363922092000@news.mit.edu>, meeroh
<macdev@meeroh.org> wrote:
| Then writing:
|
| Fun (Foo (2));
|
| is exactly the same as writing
|
| const Foo __temporary (2);
| Fun (__temporary);
Just a minor correction to meeroh's excellent explanation. The temporary
is not const.
class zurk
{
public:
zurk(int z) {zonk=z;}
void const_method() const {}
int zonk;
};
...
zurk(2).const_method(); // ok
But nevertheless, meeroh's argument holds. Ref:
13.3.3.1.4 - Reference binding
...
-3- A standard conversion sequence cannot be formed if it requires binding
a reference to non-const to an rvalue (except when binding an implicit
object parameter; see the special rules for that case in
over.match.funcs). [Note: this means, for example, that a candidate
function cannot be a viable function if it has a non-const reference
parameter (other than the implicit object parameter) and the
corresponding argument is a temporary or would require one to be created
to initialize the reference (see dcl.init.ref). ]
And yes, the comiler has gotten stricter in this regard between 5.3 and 6.
-Howard
Re: CWP6: illegal implicit conversion...
Author: Gordon Tillman
Date: Fri, 22 Sep 2000 00:00
Date: Fri, 22 Sep 2000 00:00
14 lines
1242 bytes
1242 bytes
Hi Meeroh, Thank you for the info! > It does, and that instance is always non-modifiable, i.e. const. > Therefore, it can't be passed to a function that would modify it. That's > all there is :-) Your explanation makes perfect sense and if I hadn't been so damned lazy I should have broke out my Stroustrup book and looked it up! As always I appreciate your time and trouble... --gordon
Re: CWP6: illegal implicit conversion...
Author: Ronald Webster
Date: Fri, 22 Sep 2000 06:14
Date: Fri, 22 Sep 2000 06:14
71 lines
2641 bytes
2641 bytes
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?
-Ron Webster
class zurk
{
public:
zurk(int z) {zonk=z;}
int zonk;
};
int Fref(zurk& z);
int Fcref(const zurk& z);
int Fval(zurk z);
int Fcval(const zurk z);
int Fref(zurk& z)
{
return(z.zonk);
}
int Fcref(const zurk& z)
{
return(z.zonk);
}
int Fval(zurk z)
{
return(z.zonk);
}
int Fcval(const zurk z)
{
return(z.zonk);
}
int main()
{
zurk zk(2);
int z;
z=Fref(zk); z=Fcref(zk); z=Fval(zk); z=Fcval(zk);
z=Fref(zurk(2)); z=Fcref(zurk(2)); z=Fval(zurk(2)); z=Fcval(zurk(2));
return 0;
}
meeroh wrote:
> In article <39CA6ACD.31F060CF@mindspring.com>, got@mindspring.com
> wrote:
>
> >Hello Again!
> >
> >First of all...thanks meeroh and Ronald for the updates. For some
> >reason I thought that doing this...
> >
> >> OnDraw( CP_Region(fPlatformWindow->visRgn) );
> >
> >...was still supplying an instance of CP_Region (like an anonymous one
> >or something!)
>
> It does, and that instance is always non-modifiable, i.e. const.
> Therefore, it can't be passed to a function that would modify it. That's
> all there is :-)
>
> meeroh
> --
> To get random signatures put text files into a folder called "Random Signatures" into your Preferences folder.
Re: CWP6: illegal implicit conversion...
Author: 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.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads