Re: warning C4238 : cast reference in void*
- From: "Eric" <clement.eric@xxxxxxxxx>
- Date: 2 Nov 2006 06:44:37 -0800
Alex Blekhman wrote:
Eric wrote:
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);
}
foo2 returns temporary _copy_ of CString. So, you're trying
to return an address of temporary object. This code will
crash at runtime.
Sorry all, I understand that local variable are temporary objet. My
question was more about the warning C4238 and the class rvalue, lvalue
issue.
why void* ptr = &foo2(aString) give this warning ?
Regards,
Eric
.
- Follow-Ups:
- Re: warning C4238 : cast reference in void*
- From: pj_hern
- Re: warning C4238 : cast reference in void*
- From: Jeffrey Schwab
- Re: warning C4238 : cast reference in void*
- From: Alex Blekhman
- Re: warning C4238 : cast reference in void*
- 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
- Re: warning C4238 : cast reference in void*
- From: Alex Blekhman
- warning C4238 : cast reference in void*
- Prev by Date: Re: warning C4238 : cast reference in void*
- Next by Date: Re: SMP - dual/triple/?? processor programming
- Previous by thread: Re: warning C4238 : cast reference in void*
- Next by thread: Re: warning C4238 : cast reference in void*
- Index(es):
Relevant Pages
|