C ++ Primer (two)

C ++ standard library classes and

1. Class this pointer: a member function with additional implicit parameter named this call to access its object, when calling a member function, actually this is initialized with the address of the target function, this is a constant pointer always refers to the current object.

2. const member functions: this type of class is a pointer to type const pointer version of the Constants, eg: Sales_data * const 

    Const object, the object reference or pointer constants can only call const member functions (const keyword on the back of the member function parameter list), followed by a pointer to indicate this is a constant in the back of the list of parameters const

    this is a pointer to a pointer constant, so constant member function call can not change the content of its object

    const member functions if the reference return * this, then it return type is const reference

3. Compiler two-step process categories: First, compile a statement of the members, and then the members of the body of the function. Therefore, the members of the body of the function are free to use other members of the class without having to care about the order in which the members appear

4. The default constructor initializes:

    (1) If the initial value is present within the class, use it to initialize members

    (2) Otherwise, the default initialization member

    Only when the class does not declare any constructors, the compiler will automatically generate a default constructor

    When or if the class contains built-in type composite members, only if all the members have been given an initial value within a class, it is suitable for the synthesis of the default constructor, or a default value after initialization undefined

    If within a custom class constructor want to generate a default constructor need to write the class name () = default, tells the compiler generates a default constructor

5. friend: class or other classes may be allowed access to its non-public function members

    Friend declaration: friend need to declare twice, once in the class declaration within the specified permission to access, but it is not a function declaration in the usual sense, if the user of the class can call a friend in need specifically to function outside the class a statement

6. Package:

    (1) ensure that the user code can not inadvertently damage the package state of the object

    (2) the specific implementation details can be encapsulated class changed at any time, without having to adjust the user-level code

7. Variable data members: mutable keyword modified data members, may be modified even within a const member function

8. When the class provides the initial value, must be expressed in symbols or braces = 

Guess you like

Origin www.cnblogs.com/demian/p/12097814.html