【发布时间】:2012-10-13 06:02:36
【问题描述】:
旧式转换的代码:
const string *ps;
void *pv;
pv = (void*)ps;
我尝试了三种不同的命名演员表:
pv = static_cast<void*>(ps); // error: invalid static_cast from type ‘const string* {aka const std::basic_string<char>*}’ to type ‘void*’
pv = const_cast<void*>(ps); // error: invalid const_cast from type ‘const string* {aka const std::basic_string<char>*}’ to type ‘void*’
pv = reinterpret_cast<void*>(ps); // error: reinterpret_cast from type ‘const string* {aka const std::basic_string<char>*}’ to type ‘void*’ casts away qualifiers
如您所见。没有任何效果。
【问题讨论】:
标签: c++