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.

The error message

The error message

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:

  1. Select Tools > Code Engineering > C++ Round-trip > Generate Code… from the main menu.
  2. Click Predefined macros… at the bottom of the Generate Code window.

    Open Predefined Macro Dialog

    Open Predefined Macro Dialog

  3. Now we can define the macro used in our source code in here. Press the Add button to add a new entry.
  4. 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.

    Define Macro

    Define Macro

  5. Click OK.

Now try to reverse the source code again and this time it being reversed to model successfully.

Source File being Reversed to Model

Source File being Reversed to Model

Related Links

50 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply