C + + Learning (14)

Source: Internet
Author: User

1 //Public inheritance features: the common members and protected members of the base class will be the public and protected members of the derived class, respectively2 //Private Inheritance Features: Public members and protected members in base classes are private members of derived classes, respectively3 //protected Inheritance Features: Public members and protected members in a base class are protected members of the derived class, respectively4 //Here is an example of public inheritance5#include <iostream.h>6 classa{7     Private:    8         intA1;9     protected:Ten         intA2; One      Public: A         intA3; -AintX1,intX2,intx3) { -a1=X1; theA2=x2; -a3=X3; -         } -~A () {} + }; -  + classB: Publica{ A     Private: at         intB1; -     protected: -         intB2; -      Public: -         intB3; -BintX1,intX2,intX3,intY1,intY2,inty3): A (x1,x2,x3) { inb1=Y1; -B2=Y2; tob3=Y3; +         } -~B () {} the  *         voidPrint ()Const{ $             //cout<< "a1=" <<a1<<endl;//illegalPanax Notoginsengcout<<"a2="<<a2<<Endl; -cout<<"a3="<<a3<<Endl; thecout<<"b1="<<b1<<Endl; +cout<<"b2="<<b2<<Endl; Acout<<"b3="<<b3<<Endl; the         } + }; -  $ voidShow (B &MyB) { $     //cout<< "myb.a1=" <<myB.a1<<endl;//illegal -     //cout<< "myb.a2=" <<myB.a2<<endl;//illegal -cout<<"myb.a3="<<myB.a3<<Endl; the     //cout<< "myb.b1=" <<myB.b1<<endl;//illegal -     //cout<< "myb.b2=" <<myB.b2<<endl;//illegalWuyicout<<"myb.b3="<<myB.b3<<Endl; the } -  Wu intMain () { -     return 0; About}

C + + Learning (14)

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.