C + + Eighth day Note February 25, 2016 (Thursday) a.m.

Source: Internet
Author: User

1. Inheritance:A Class A can inherit another class B, then we call Class B the base class (the parent Class), and Class A is a derived class (subclass). 2. Derived classes inherit all members from the base class, except constructors, destructors, and = functions. 3. Private members of the base class, although they are also private members of derived classes, cannot be accessed by member functions defined in the derived class. Private members of these base classes can only be accessed through the public member functions of the base class. 4. Subclasses can implement their own members of the same prototype as the parent class member functions (function name, parameter list)functions, called Overrides. Overrides are exceptions to function overloading, and overrides must occur in the process of inheritance. when calling the overridden parent version of a function in a subclass, add base to the function name:: (base class name base) such as point:: 5. Constructors in derived classes6. Protected:members modified by protected can only be accessed directly from the current class and its derived classes, and other classes or functions are still not visible.  attached Source:
1#include <iostream>2 3 using namespacestd;4 classbase{5  Public:6Base (inti): B_number (i) {}7     intGet_number ()Const{returnB_number;}8     voidprint () {9cout<<b_number<<Endl;Ten     } One //Private: A protected: -     intB_number; - }; the classDerived: Publicbase{ -  Public: -Derived (intIintj): Base (i), D_number (j) {} -     voidprint () { + //cout<<get_number () << ""; -cout<<b_number<<" "; +cout<<d_number<<Endl; A     } at Private: -     intD_number; - }; - intMainintargcConst Char*argv[]) { -Base A (2); -Derived B (3,4); incout<<"a is"; - a.print (); tocout<<"b is"; + b.print (); -cout<<"base Part of the B is"; the b.base::p rint (); *     return 0; $}

C + + Eighth day Note February 25, 2016 (Thursday) a.m.

Related Article

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.