What's the named cast equivalent for the following old-style cast?
const string *ps;
void *pv;
pv = (void*)ps; // <--- this
Is it pv = static_cast<void*>(const_cast<string*>(ps));
?
pv = const_cast<string *>(ps);
is good enough - void *
is implicitly assignable from any (non-qualified) data (object) pointer type.
(Of course, for the same reason, a direct assignment to const void *
without any casting would work.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.