C++ Template generation to cpp file?

General discussions about code engineering

Moderator: Moderators

C++ Template generation to cpp file?

Postby bobo1@hotmail.com » Wed May 27, 2015 3:11 pm

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?
bobo1@hotmail.com
Forum Newbie
Forum Newbie
 
Posts: 5
Posts Rating:0
Joined: Fri May 22, 2015 10:32 pm

Re: C++ Template generation to cpp file?

Postby bhoomchai » Fri May 29, 2015 2:41 am

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
bhoomchai
Customer Support
Customer Support
 
Posts: 36
Posts Rating:5
Joined: Thu Jan 21, 2010 12:38 am


Return to Code engineering

Who is online

Users browsing this forum: No registered users and 1 guest