Applied to pointers to classes, that is to say that it allows to cast a pointer of a derived class to its base class (this is a valid conversion that can be implicitly performed) and can also perform the inverse: cast a base class to its derivated class.
In this last case the base class that is being casted is not checked to determine wether this is a complete class of the destination type or not.
Code:
class Base {};
class Derived : public Base {};
Base *a = new Base;
Derived *b = static_cast
'static_cast', aside from manipulating pointers to classes, can also be used to perform conversions explicitly defined in classes, as well as to perform standard conversions between fundamental types:
No comments:
Post a Comment