Code with old style cast:
const string *ps;
void *pv;
pv = (void*)ps;
I have try three various named casts:
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
As you can see. Nothing works.
In this special case, it’s simply:
The conversion from
string*tovoid*is implicit. If you wanted tomake it explicit, you’d need a second, separate cast:
or
I don’t think making it explicit is particularly necessary, however; the
fact that you’re using a
void*already says that there will beconversions.