One: access rights for private, protected, and public issues:
Private:1, a member function in a class can be called, 2, a friend function of a class can be called, 3, but the class object cannot be called directly. 4. For derived classes, neither the member function nor the object of the derived class can be called.
A member function in a protected:1 class cannot be called, 2, a friend function of a class can be called, and 3, a class object cannot be called. 4. For derived classes, member functions can be called, but objects of derived classes cannot be called.
Public:1 can be called by a member function in the class, 2, the friend function of the class can be called, 3, the class object can also be called directly. 4, for derived classes, member functions and derived classes of objects can be called.
Note: The friend function consists of 1, a normal non-member function set as a friend. 2. member functions of other classes that are set as friends. 3, set as all member functions of the friend class.
Two: Questions about the succession of private, protected and public:
1, whether private, protected, or public, the subclass inherits the base class, which inevitably inherits all the members of the base class (except the constructor and destructor of the base class), and inherits the size of the base class space.
#include <iostream>using namespacestd;classa{ Public: A () {cout<<"this is class A."<<Endl; }Private: intA; inttemp;};classD |Privatea{ Public: B () {cout<<"this is class B."<<Endl; }Private: intb;};voidMain () {cout<<sizeof(A) <<Endl; cout<<sizeof(B) <<Endl;}
example of change in capacity size after inheritance:
2. After the class inherits, the property changes.
The private property can be inherited, but it cannot be directly invoked under any circumstances (except the public member function of the base class and the friend function of the base class);
With private inheritance, the protected and public properties of the parent class become private in subclasses;
With protected inheritance, the protected and public properties of the parent class become protected in the subclass;
With public inheritance, the protected and public properties in the parent class do not change;
As shown below: Public:protected:private:
Public inherited public protected not available
Protected inherited protected protected not available
Private private is not available
Analysis of C++:private, protected and public