How can I use pure virtual methods in external C++ declared within a process model?

Categories:
Solution Number:
S20796
Last Modified:
2013-08-20
Issue

How can I use pure virtual methods in external C++ declared within a process model?

Solution

[Note: This is applicable for older versions of g++. Nothing special needs to be done with g++ 3.3 and later.]According to FAQ #552, point A.2, some portions of I/O stream libraries mustbe explicitly linked with the OPNET Modeler executable by linking a dummyfunction that contains the required functionality. You must do this for specific functionality that you want to use that requires portions of these C++ libraries that are not linked automatically.You must also do this if you wish to use a pure virtual method within external C++ code that is declared within a process model. g++ internally links a library so that the pure virtual keyword is recognizable when a program is executed. This is not done when C++ code is compiled using op_mko and then used within a process model. When the simulation is run, the symbol __pure_virtual is not recognized.However, if you compose a dummy .cpp file that defines a class with a pure virtual method, and compile this file using g++ -c to get a .o file, then link this .o file with the OPNET Modeler executables(op_runsim_dev and op_runsim_opt) by following the same steps as in FAQ forlinking I/O streams, the pure virtual method can then be used.The base class dummy .hpp file could look something like this:class baseClass{virtual void testFunc() = 0;};The derived class .hpp file could look something like this;class derivedClass : public baseClass{void testFunc();}And the derived class .cpp file could look like this:void derivedClass::testFunc(){}Compile the derived class .cpp file with g++ -c, then link the .o filewith the OPNET Modeler executables the same as you link the dummy_iostream.ofile following FAQ #552.

Environment

DES Kernel->Process Modeling/Coding

Attachments
NOTICE: Riverbed® product names have changed. Please refer to the Product List for a complete list of product names.
Can't find an answer? Create a case