5 C ++ inheritance Design for ibm rsa (IBM Rational Software Architect) V8

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.