- Main Page
- Modules
- Classes
- Files
- Directories
- Related Pages

# Functions

template<class T>
T | check_and_cast (cPolymorphic *p)

## Function Documentation

template<class T>
T check_and_cast | ( | cPolymorphic * | p | ) |

| Cast an object pointer to the given C++ type and throw exception if fails. The method calls dynamic_cast<T>(p) where T is a type you supplied; if the result is NULL (which indicates incompatible types), an exception is thrown. In the following example, MyPacket is a subclass of cMessage, and we want to assert that the message received is actually a MyPacket. If not, the simulation stops with an error message as the result of the exception.
       cMessage *msg = receive();
       MyPacket *pkt = check_and_cast<MyPacket *>(msg);