TYPE* dynamic_cast<TYPE*> (object);
If you attempt to cast to pointer to a type that is not a type of actual object, the result of the cast will be NULL
C++
#include <string>
class Location
{
public: virtual ~Location() { }
public: std::string m_Street;
public: std::string m_City;
};
class Shop : public Location
{
public: virtual ~Shop() { }
public: std::string m_ShopName;
};
int main()
{
Location* pL = new Shop();
Shop* pS = dynamic_cast<Shop*> (pL); // converting pointer of Location class to Shop class
if (pS != NULL)
{
pS->m_ShopName = "Booking shop";
}
}