简体   繁体   中英

How use static_cast with double casting

How can I use static_cast with casting types like that:

CString response;
resultData = (void *) (const char *) response;

where result data is type void *& .

I tried to do to this in following way:

resultData = static_cast<(void*)(const char*)>(response);
resultData = static_cast<void*>(static_cast<const char*>(response));

but it doesn't work.

Do you have any ideas?

You either need to cast to const void * :

resultData = static_cast<const void*>(static_cast<const char*>(response));

Or you need to use const_cast (which is needed to remove const , static_cast cannot remove it):

resultData = static_cast<void*>(const_cast<char *>(static_cast<const char*>(response)));

Note: if your resultData is void * , then the cast to void * is not needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM