Class A;
Class Members:
1. Function members
Constructor: A special member function that cannot be declared as a const
The constant pointer this:this type is "a *const" and always points to the "this" object that invokes the member function;
Const member function: Used to modify the type of the implicit this pointer, modified after the this pointer type is "const A *const". Equivalent to the this pointer added " Bottom const", can cause overloading;
The function that returns the This object:
/* Note the return type and the return statement */ & Sales_data::combine (const Sales_data &RHS) {... return *this; // Dereference this pointer }
Const can cause overloading
Not finished ...
2. Data members
Typically encapsulated as in the "private" part, the private part encapsulates (that is, hides) the implementation details of the class.
Variable data member (mutable keyword ): For variable data members, any member function, including the const function, can change its value within.
class screen{public: voidconst; // Const member Functions Private : mutable size_t access; // Variable data members }voidconst{ ++access; // Change Access}
initial value in class : When we provide an initial value in a class, we must use "=" or curly braces.
3. Type Members
class screen{public: typedef std::string:: Size_type pos; // type member pos Private : pos cursor=0; pos Height=0; std::string contents;
A class can customize an alias for a type in a class, and the type alias defined by the class has access restrictions (public or private) like other members;
The members used to define the type must first be defined and used, usually where the class begins !
4. Friends
A friend declaration is placed in the same header file as the class itself;
In order for a friend to be visible to the user of the class, the function is specifically declared once outside the class (in addition to the friend declaration inside the class);
Private members of the class can be accessed, and private data members of the class can be overwritten. Abusing a friend destroys the encapsulation of a class.
C + +-class