Every C and C++ programmer is familiar with the C style cast syntax:


When C++ introduced constructors, it also introduced the functional style cast syntax:


The problem with both of these is that the compiler just believes you and goes ahead and converts the expression to the specified type. Ideally, you want more control. For example, if you simply want to cast away const (heaven forbid!), you don't want to accidentally perform some other conversion:

	const Y* yp;
	X* xp = (X*)yp;	// oops!

Bjarne Stroustrup proposed, and the committee accepted, three new types of cast that provide a level of type safety.

const_cast ensures that you only change the const qualification in a conversion - if you tried to use const_cast in the example above, you'd get a compiler error.
static_cast allows you to perform any conversion where there is an implicit conversion in the opposite direction - it allows you to perform conversions between related types in a meaningful way.
reinterpret_cast allows any conversion and generally indicates a representation change. It lets you do any cast that is not allowed by either const_cast or static_cast.
The syntax is controversial, however. If you already dislike templates, you'll hate the new syntax:

	Y* yp2 = const_cast<Y*>(yp);
	X* xp = static_cast<X*>(yp2);
		// only valid if X and Y are related types
	char* cp = reinterpret_cast<char*>(xp);
		// ignore meaning of types

There's also dynamic_cast which is part of the runtime type identification mechanism.