首页 > 其他 > 详细

static_cast void* - > string

时间:2018-11-22 19:35:36      阅读:117      评论:0      收藏:0      [点我收藏+]
// Cast a dynamically allocated string to ‘void*‘.
void *vp = static_cast<void*>(new std::string("it‘s easy to break stuff like this!"));

// Then, in the function that‘s using the UserEvent:
// Cast it back to a string pointer.
std::string *sp = static_cast<std::string*>(vp);//vp=void*
// You could use ‘sp‘ directly, or this, which does a copy.
std::string s = *sp;
// Don‘t forget to destroy the memory that you‘ve allocated.
delete sp;

static_cast void* - > string

原文:https://www.cnblogs.com/wllwqdeai/p/10003321.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!