2013Asker
2013Asker

Reputation: 2068

C++ What's the named cast equivalent

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)); ?

Upvotes: 2

Views: 397

Answers (1)

user529758
user529758

Reputation:

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.)

Upvotes: 7

Related Questions