How to Reverse C++ Source with Predefined Macros
Visual Paradigm for UML supports round-trip engineering on C++ source file. But when you reverse C++ source code into class model, you may receive some strange error message complain there are syntax problem in your source file. This probably caused by the predefined macros in your source code. This article will teach you what you should configure in order to reverse your source code into class model.
From the error message showing in above screenshot, it complains the error is on line 9. Now let’s have a look to the source code.
1 | #include <QObject> |
2 | |
3 | namespace a { |
4 | namespace b { |
5 | namespace c { |
6 | |
7 | class Test : public QObject { |
8 | Q_Object |
9 | private: |
10 | int a; |
11 | clar b; |
12 | public: |
13 | Test(int a, char b); |
14 | int getA(); |
15 | char getB(); |
16 | }; |
17 | }}} |
The line 9 shouldn’t cause any syntax error. But go up to line 8, we have the Q_Object defined. This obviously is the one causing problem.
To solve this problem:
- Select Tools > Code Engineering > C++ Round-trip > Generate Code… from the main menu.
- Click Predefined macros… at the bottom of the Generate Code window.
- Now we can define the macro used in our source code in here. Press the Add button to add a new entry.
- Enter Q_Object to the Name cell, and fill in the implementation of the macro in the Value cell. You can also leave the Value cell empty and VP will treat it as an empty macro.
- Click OK.
Now try to reverse the source code again and this time it being reversed to model successfully.
Leave a Reply
Want to join the discussion?Feel free to contribute!