Original http://blog.csdn.net/ztz0223/article/details/7599935
In fact, the entire seriesArticleI want to give myself a memo, but I have a poor memory and post a message. It is also convenient for students who love learning.
Next, let's talk about the class design of C ++ and generate C ++.Code:
4 C ++ class diagram converted from ibm rsa (IBM Rational Software Architect) V8 modeling learning to C ++ code
In the previous article, I have created a class chart that can generate C ++ struct code. Then I create a class inheritance and create a new class. The base class uses the my_struct struct. The new class is derived_my_struct and a member is added as d_mem and char, the whole process class design is only a method of use, and examples, does not represent any practical significance.
Save all, double-click tc1.tc in "Project Resource Manager", and click "run" to generate C ++ code. As follows:
No problem. Everything is OK.
Now, the inheritance relationship diagram is actually not as easy as you think. Let's look at it.
Select "select board" and select "Generalized relationship ":
The inheritance relationship between the two classes created by the connection:
Save all the files, select tc1.tc, and click Run to generate the C ++ inheritance code, as shown below:
It is strange that the generated code is private inheritance. What should we do if we want to inherit in total? Is there a way to create a common inheritance and protect the inheritance in this general relationship?
Haha, of course there is a solution.
The operation is as follows.
Select the inherited arrow and click "constructor" in the attribute column below to add a type. Of course, only one type is available, that is, cpp_generalization, how to translate it into Chinese? -- C ++ generalization? It doesn't matter. Click OK:
Click "advanced" in the "attribute bar", and the following C ++ attributes will be displayed:
Do not modify isvirtual. Keep it false. If it is true, it means virtual inheritance. The generalized type (generalizationkind) has 0-Public 1-protected 2-Private 3-default. These are the inheritance attributes corresponding to C ++.
Here, we will try protection inheritance.
Then generate the C ++ code to see the effect:
There is no problem with the selection of the inherited code.
Or that sentence,Everything is so beautiful, haha.