Friday, February 5, 2010

What is the difference between dynamic and static casting?

static_cast are used in two cases:
1) for implicit casts that the compiler would make automatically anyway (bool to int) 
2) as a mandatory forced cast (float to int).
dynamic_cast is unique to C++. It is used at runtime when info is required to make the proper cast. For eg, when you downcast a base class pointer to a derived class.

0 Comments: