static_cast versus C-style type cast

D

Dave Rahardja

Is there a difference between a static_cast and an C-style type cast?

In other words, is there a difference between...

int a;
unsigned b = static_cast<unsigned>(a); // static_cast
unsigned c = (unsigned)(a); // C-style cast
 
R

Rolf Magnus

Dave said:
Is there a difference between a static_cast and an C-style type cast?
Yes.

In other words, is there a difference between...

int a;
unsigned b = static_cast<unsigned>(a); // static_cast
unsigned c = (unsigned)(a); // C-style cast

No.
A static_cast is more restrictive than a C style cast. The latter will
do the same as any combination of static_cast, const_cast and
reinterpret_cast that is necessary for the requested convertion.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top