Re: warning C4238 : cast reference in void*
- From: "Eric" <clement.eric@xxxxxxxxx>
- Date: 2 Nov 2006 06:12:16 -0800
Eric wrote:
Ulrich Eckhardt wrote:
Eric wrote:
void foo(void* param)[...]
foo((void*) &szWord); //give C4238 warning : nonstandard extension
used : class rvalue used as lvalue
1. For your own sake, forget about the fact that C-style casts like the
above exist. I haven't found the need for one in over 1M lines of code and
you surely don't have such a case here.
Conversion from a typed pointer to a void pointer is implicitly done by the
compiler, so a cast isn't necessary. If you absolutely want, use a
static_cast, which is also the right cast to convert to a typed pointer
again.
2. Igor already mentioned it, this can't be the code you tried to compile,
please show the real code for an analysis of its problems.
Uli
Thanks all, sorry I didn't give you the good code.
CString foo2(CString aString)
{
return aString;
}
void* foo(CString &aString)
{
return (void*)&foo2(aString); //give C4238 warning
}
int main()
{
CString aString;
void* ptr = foo(aString);
}
Eric
I don't understand this warning, but I find that a use of an
intermediate variable for cast the string in void* solve the warning.
.
- References:
- warning C4238 : cast reference in void*
- From: Eric
- Re: warning C4238 : cast reference in void*
- From: Ulrich Eckhardt
- Re: warning C4238 : cast reference in void*
- From: Eric
- warning C4238 : cast reference in void*
- Prev by Date: Re: warning C4238 : cast reference in void*
- Next by Date: Re: warning C4238 : cast reference in void*
- Previous by thread: Re: warning C4238 : cast reference in void*
- Next by thread: Re: warning C4238 : cast reference in void*
- Index(es):
Relevant Pages
|