Inheritance and derivation (1)--the relationship between classes and classes, basic concepts of inheritance

Source: Internet
Author: User

1. The relationship between classes and classes

  Has-a,uses-a and Is-a

Has-a contains relationships that describe a class consisting of multiple "part classes". Implementing a has-a relationship is represented by a class member, that is, the data member in one class is another class that has already been defined.

Uses-a one class to use the other class partially. Define a friend or object parameter delivery implementation through the interaction of member functions between classes.

The is-a mechanism is called "inheritance." The relationship is transitive and not symmetric.

classa{ Public:    voidFunca () {}intA;};//Class B has a member variable of Class A, B has A, Class B depends on Class Aclassb{ Public:    voidFUNCB () {} a A;};//the member method of Class C requires the formal parameter of Class A, C use a, Class C depends on Class Aclassc{ Public:    voidFUNCC (A *a) {}voidFUNCCC () {}};//Class D inherits from Class A, class D if it is inheriting Class A, Class D is Class A, Class C inherits from Class A, and the coupling is very highclassD: Publica{ Public:    voidFuncd () {cout<< a <<Endl; }};
2, the basic concept of inheritance

Inheritance and derivation (1)--the relationship between classes and classes, basic concepts of inheritance

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.