cObjectcreateOne (const char *classname)
cObjectcreateOneIfClassIsKnown (const char *classname)
template<class T >
check_and_cast (cObject *p)
template<class T >
const T check_and_cast (const cObject *p)

Function Documentation

template<class T >
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().

Generated on Tue Dec 2 11:16:27 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3