All those things are standard C++ operators. They might be used in windows programming, but that's only because they are standard C++ and some windows programmers presumably do things that require their behaviour.
dynamic_cast<T>(v) converts the expression v so it is of type T. T can only be a pointer or reference to a complete class type (i.e. not int, double, etc and not a forward declaration for a class) or pointer to cv void (cv means it can be qualified as const or volatile). The logic of how dynamic_cast works is (straight from the standard);
-- If, in the most derived object pointed (referred) to by v, v points (refers) to a public base class subobject of a T object, and if only one object of type T is derived from the subobject pointed (referred) to by v, the result is a pointer (an lvalue referring) to that T object.
-- Otherwise, if v points (refers) to a public base class subobject of the most derived object, and the type of the most derived object has an unambiguous public base class of type T, the result is a pointer (an lvalue referring) to the T subobject of the most derived object.
-- Otherwise, the runtime check fails.
If T is a pointer, a failed dynamic_cast yields a NULL pointer. If T is a reference, a std::bad_cast exception is thrown.
For example;
Code:
class B {};
class D : public B {};
int main()
{
B *x = new D;
if (dynamic_cast<D *>(x) == NULL) std::cout << "x is of type D\n";
}
This code will always report that x is of type D.
The important thing about dynamic_cast<> is that it provides a runtime check of type of an object. Hence it is sometimes used in object libraries (eg under windows it might be used to check that a pointer to Widget actually pointers to a Button).
static_cast<T>(v) converts expression v to be of type T, at compile time.
reinterpret_cast<T>(v) is used to convert expressions v to type T. It only works for specific cases of converting integral values to pointers, and pointers so they can be stored in integral types (int, unsigned, etc). The behaviour is compiler dependent but can be used (say) to print a value of a pointer. If reinterpret_cast is used to convert a pointer to an integral type, and used again to convert back to the pointer type, then the original pointer will come back. Information can, however, be lost if the pointer and integral types are of different size (eg a 16 bit int can't hold a 32 bit pointer).
Unlike the other _cast, const_cast is used to change constness. For example,
Code:
int do_something(const int &x)
{
int &y = const_cast<int &>(x);
y = 42; // now allowed to modify x
}
Keep in mind that the above code yields undefined behaviour. It allows the function to modify a const argument. The const_cast<> does not make changing x safe; it simply stops the compiler from complaining at the attempt to change x (though y). The most common usage of const_cast is when using an old library in a new one;
Code:
int SomeFunctionFromOldLibrary(int &x)
{
// this function does not actually change x
}
int SomeFunction(const int &x)
{
SomeFunctionFromOldLibrary(const_cast<int &>(x)); // allow us to call SomeFunctionFromOldLibrary() as we trust it not to modify x
}
typeid(x) gives information (in a structure of type std::type_info, which is declared in the header <typeinfo>) about the type of an object. It only works for class types. type_info objects can be compared (eg they are not equal if two objects are of different types) and a name() method gives a string which identifies the type (the content of that string is compiler dependent though).