Test the access permission of a derived class member function in inheritance

Source: Internet
Author: User

The derived class does not have access permission to the private member of its base class, and does not have access permission to the protected member of the base class object) private and protected members have access permissions.

Because c ++ has a poor foundation and does not need it at ordinary times, a very critical error is corrected today. The class access permission is for the class, instead of for class objects. I have always understood it wrong. I have no face to write this sentence, but I still want to write it down.

The following is a simple test code. The access permissions of the objects test, basic class parameters, and derived class parameters that call member functions are tested as follows:

# Include <iostream> using namespace STD; class base {public: int pub; protected: int pro; private: int pri ;}; class derive: public base {public: int newpub; protected: int newpro; private: int newpri; public: int func (class base A, class derive B) {/////////////////////////////////////// /// test the cout <newpub <Endl; cout <newpro <Endl; cout <newpri <Endl; cout <pub <Endl; cout <pro <Endl; // No access cout <pri <Endl; //////////////////////////////////////// /test the cout of the base class object access permission <. pub <Endl; // No access cout <. pro <Endl; // No access cout <. PRI <Endl; //////////////////////////////////////// /test cout for the access permissions of the base class and non-base class members of the derived class Object <B. pub <Endl; cout <B. pro <Endl; // No access cout <B. PRI <Endl; cout <B. newpub <Endl; cout <B. newpro <Endl; cout <B. newpri <Endl; //////////////////////////////////////// return 0 ;}}; int main () {class base A; Class derive B; Class derive test; test. func (a, B); Return 0 ;}

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.