码迷,mamicode.com
首页 > 其他好文 > 详细

static_cast void* - > string

时间:2018-11-22 20:55:46      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:call   directly   strong   this   using   ati   like   dynamic   rev   

// 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

标签:call   directly   strong   this   using   ati   like   dynamic   rev   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!