简体   繁体   English

如何将static_cast与双播配合使用

[英]How use static_cast with double casting

How can I use static_cast with casting types like that: 如何将static_cast与这样的转换类型结合使用:

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

where result data is type void *& . 结果数据的类型为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 * : 您要么需要强制转换为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): 或者您需要使用const_cast (删除const所需, static_cast无法删除它):

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. 注意:如果你的resultDatavoid * ,然后投给void *是没有必要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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