"C ++ Primer Third Edition" Reading Note - Chapter 2 C ++ View

zhaozj2021-02-16  72

1. The member function defined in the class definition will be automatically treated as an inline function.

2, P30: "Every class object is automatically called after the last use of the program lasts." I think this sentence has some misleading effects. Look at the following program:

#include

Class test {public: test () {}; ~ test () {cout << "end test!" << endl;} void print () {cout << "print ()" << endl;}};

INT main () {test t; t.print (); // Last use of cout << "code end!" << endl; return 0;}

If you say in the book, the output should be:

PRINT () end test! code end!

However, the results in VC 6 are:

Print () code end! End Test!

Therefore, the destructor should be called when the class object is released.

3. The member function placed in the C source file is not used to recompile with each program that uses the related class, and they are saved in the class library after precompilation.

4, constructor and destructive functions neither the object that is not destroyed (the compiler automatically acts on these objects). The memory used to maintain the data member in the maintenance class has been assigned before the constructor is applied. The constructor of the class is mainly used to initialize the data of the class object, and the destructor is responsible for the release of all the resources applied in the life period.

5, efficiency and function are often uncomfortable.

6. Data members and member functions in the protection area of ​​the class, not provided to the general procedure, only to derived classes. Members in private areas in the base class can only be used by this class, and derived categories cannot be used.

7. Decision for virtual function calls should wait until the running moment.

8. If the derived class does not introduce a data member that requires a description, there is no need to explicitly provide a destructor. (Because it is handled by the destructor of its base class.)

9. The virtual function cannot be inline, because the inline is in the compilation time, so the efficiency of the virtual function is low relative to the non-virtual function.

10, exception happened at runtime.

11. If the New failed, the standard library will generate an exception of the Bad_alloc standard.

12. By default, the TERMINATE () ends the program.

13. It is recommended to use a USING declaration with a fine selection function instead of the USING indicator.

14. To use a generic algorithm, need header files:

#include

转载请注明原文地址:https://www.9cbs.com/read-16036.html

New Post(0)