c++ - '<function-style-cast>' : cannot convert from 'int' to 'CString' -
this code written in visual studio 2003, compile in 2008.
int afxapi afxmessagebox(lpctstr lpsztext, uint ntype = mb_ok, uint nidhelp = 0); if(iirecd == socket_error || iirecd == 0) { ierr = ::getlasterror(); afxmessagebox(cstring(ierr)); goto prereturncleanup; }
in 2003, works fine, in 2008, shows me error:
error 50 error c2440: '<function-style-cast>' : cannot convert 'int' 'cstring'
what error mean?
it's bit hard without information, erroneous code , want there.
here's guess: want convert int
cstring
, somehow this:
int = 42; cstring str = (cstring)i;
if you're using mfc/atl cstring try following
int = 42; cstring str; str.format("%d", i);
cstring::format takes format string printf
, stores result in cstring.
edit
i'm interpreting comment below code causes error. bit surrounding text , explanation nice, though.
if(iirecd == socket_error || iirecd == 0) { ierr = ::getlasterror(); afxmessagebox(cstring(ierr)); goto prereturncleanup; }
try change to
if(iirecd == socket_error || iirecd == 0) { ierr = ::getlasterror(); cstring msg; msg.format("%d", ierr); afxmessagebox(msg); goto prereturncleanup; }
one general comment on goto prereturncleanup;
: may want take @ raii-idiom (imho) better way such cleanup.
Comments
Post a Comment