Page 1 of 1

C++ Template generation to cpp file?

PostPosted: Wed May 27, 2015 3:11 pm
by bobo1@hotmail.com
When I use MagicDraw to generate c++ code, MagicDraw creates both a ".cpp" and a ".h" file. When the code generated is for a "template" class or contains "template" functions, the results do not link.

When a template class has operations defined or a class contains template-functions, MagicDraw places stubs for implementation of the operations into the generated .cpp file. Shouldn't these stubs be kept in the .h file since the template types that will be used are defined by the template bindings in the generation of other classes? Placing the template implementations into the .cpp file causes link errors when the code is compiled/linked.

Is this a bug? Does anyone know how MagicDraw recommends resolving this problem? Similarly, it appears that MagicDraw doesn't provide for a way to output the template file as a ".hxx". Is that true? So the only way to do it is by manually renaming the file after it is created, right? Does MagicDraw recognize a difference between the c++ template files generated and the plain header files?

Re: C++ Template generation to cpp file?

PostPosted: Fri May 29, 2015 2:41 am
by bhoomchai
The stubs for implementation of the operation is generated to .cpp by default, however, this can be changed by manipulating the Realization from Component in FileView package.
By default, when you add a class to code engineering set, you will see that two component .h and .cpp are created in the FileView package. If the class contains an operation, you will see that there is a Relization from the cpp component to the operation. This will direct the code generator to generate the stub of implementation in .cpp file. So, if you delete the Realization and create a new one from .h component to the operation instead and generate the code, you will get the stub of implementation in .h file instead.
Regarding the file extension, that is correspond to the name of Component in FileView package. You can just rename it in your model and generate code again.

Best regards,
No Magic Customer Support