Modules | |
String-related | |
Functions | |
cObject * | createOne (const char *classname) |
cObject * | createOneIfClassIsKnown (const char *classname) |
template<class T > | |
T | check_and_cast (cObject *p) |
template<class T > | |
const T | check_and_cast (const cObject *p) |
T check_and_cast | ( | cObject * | p | ) | [inline] |
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);
References cObject::getClassName(), and cObject::getFullPath().
Referenced by check_and_cast().