旧式演员的代码:
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
如你看到的。没有任何效果。