1. Functions defined inside the class implicitly feel inline, the inline function should be defined in the header file, because its definition must be visible to the compiler, so that the compiler can expand the code of the function within the call point.
At this point, only the function prototype is not enough.
2.assert
3. Exceptions
4. Because the stream object cannot be copied. Therefore, it cannot be stored in a container, because the stream cannot be copied. Therefore, the shape or return type cannot be a stream type and must be either a pointer or a reference. Reading and writing to an Io object alters its state, so the reference must be non-Const.
5. If you need to reuse a file stream to read and write multiple files, you must call clear to clear the state of the stream before you read the file.
6. Forward statement.
After the declaration. Defined before. A class is an incomplete type. That is, it is known that it is a type, but does not know which members are included.
Not all types can only be used in a limited way.
An object of this type cannot be defined. An incomplete type can only be used to define pointers and references to that type, or to declare (rather than define) a function that uses that type as a type or return type.
Before the object of the class is created. The class must be defined in its entirety. The class must be defined, not just the class, so that the compiler will reserve the corresponding storage space for the object of the class. Similarly, you must define a class before you use a member of the reference or pointer class.
7. You cannot return a generic reference to a class object from a const member function. The const member function can only return *this as a const reference.
8. Referencing global variables
int height;void dummy (int height) { :: height = 1;}
The function sets the global variable height to 1 instead of the parameter height of 1.
9. You must use initialization for whatever members of a const or reference type member and class type that do not have a default constructor.
10. It is a good idea to write a constructor initialization list in the same order as the member declaration. Also, avoid using members to initialize other members as much as possible.
11. In fact, assuming that other constructors are defined, it is almost always right to provide a default constructor function. Typically, the initial value provided to a member in the default constructor should indicate that the object is "empty".
12. Friends are not members of the class that is granted a friend relationship, so they are not affected by the access control that is part of their declaration. Usually. It is a good idea to put friend declarations in groups to start or end of a class definition. A friend can be a normal non-member function, or a member function of another class defined earlier. or the entire class.
The 13.static function does not have the this pointer, not any part of the object, and cannot be declared as Const. cannot be declared as a virtual function.
14.static data members must be defined outside the class definition body
15. Copy constructors can be used to initialize elements in a sequential container, such as
Vector<string> Svec (5);
The compiler first uses the string default constructor to create a temporary value to initialize the Svec, and then copies the temporary values to each element of the Svec using the copy constructor.
16. To prevent replication, the class must explicitly declare its copy constructor as private. Let's say you want to disable the replication of friends and members. Is able to declare a private copy constructor but is not properly defined. This causes an error when linking.
17. A class object that does not consent to replication can only be passed as a reference to a function or returned from a function. They also cannot be used as elements of a container.
18. The elements in the container are always reversed in reverse order, and the element labeled Size ()-1 is first revoked. The last element is the subscript 0.
19. Three rule: refers to the assumption that the destructor is required, you also need to assign the operator and copy constructor.
20. The composition destructor does not delete the object that the pointer member points to.
21. The destructor has no return value and no formal participation. Destructors cannot be overloaded because they cannot be specified, no matter what the shape participates. Although a class can define multiple constructors, it can only provide a destructor. Applies to all objects of the class.
22. An important difference between a destructor and a copy constructor or assignment operator is that, even if we write our own destructor, the composition destructor is still executing. As we have written an empty destructor. The members of the class can also be revoked by the composition destructor.
The composition destructor executes after its own definition of the destructor function.
23. Most C + + classes use one of the following three methods to manage pointer members:
(1) The pointer member takes the normal pointer type behavior. This class has all the drawbacks of pointers but does not require special replication control.
(2) Classes can implement so-called "smart pointer" behavior.
The object that the pointer points to is shared. But classes can prevent dangling pointers.
(3) class takes the value type behavior.
The object that the pointer points to is unique and is managed independently by each class object.
24. Operators that cannot be overloaded
:: .* . ?
:
25. The overloaded operator must have at least one class type or operand of the enumerated type. This rule forces the overloaded operator to define the meaning of the operator for the built-in type object again.
26. The precedence, associativity, or number of operands of an operator cannot be changed. In addition to the function call operator operator (), it is illegal to use default arguments when overloading operators.
27. An overloaded function as a member of a class. The shape participation looks 1 less than the operand. The operator as a member function has an implied this parameter, which is limited to the first operand.
Arithmetic and relational operators are generally defined as non-member functions, and assignment operators are defined as members.
28. Overloading commas, fetch addresses, logical and, logical, or equal operators is usually not a good practice. These operators have a practical meaning, and if we define our own version numbers, we cannot use these built-in meanings.
29. When an overloaded operator does not have a significant meaning. It's better to take a name for the operation. For very few operations, using a named function is usually better than using an operator. Assuming it is not a normal operation, it is not necessary to use operators for brevity.
30. The type of the Management container key type and the order container should define the = = and the < operator, on the grounds that many algorithms assume that these operators exist. For example, the sort algorithm uses the < operator. The find algorithm uses the = = operator.
31. When the class defines the subscript operator. It is generally necessary to define two version numbers: One is a non-const member and returns a reference, and one is a const member and returns a const reference.
32. The type conversion function must be a member function, cannot specify a return type, and the form reference must be empty. Although a conversion function cannot specify a return type, each conversion function must explicitly return a value of the specified type. For example, operator int returns an int value. Conversion functions should not normally alter the object being converted.
Therefore, the conversion operator should typically be defined as a const member.
33. Class type conversions cannot be followed by another class type conversion. Assuming that multiple class-type conversions are required, the code will fail.
34. Derived classes can only access the protected members of their base classes through derived class objects. Derived classes do not have special access rights to the protected members of their base class type objects.
35. When a derived class virtual function calls the base class version number. You must explicitly use the scope operator. Assuming that the derived class function ignores this, the function call is determined at execution time and will be a self-invocation, resulting in infinite recursion.
36.private inheritance is able to use the form of using BASE::XX in the public portion of a derived class. Allows private members of the base class to be interviewed by the user.
37. Derived classes defined with the class reserved word have private inheritance by default, and classes defined with struct reserved words have public inheritance by default.
38. A friend relationship cannot be inherited. The friend of the base class does not have special access rights to the members of the derived class. Assuming that the base class is granted a friend relationship, only the base class has special access permissions, and the derived class of the base class cannot visit the class that grants the friend relationship.
39. Assuming that the base class defines a static member, there is only one such member in the entire inheritance hierarchy. Each static member has only one instance, regardless of how many derived classes derive from the base class.
40. The reason that a constructor can only initialize its direct base class is that each class defines its own interface. A derived class constructor cannot initialize a member of a base class and should not assign a value to its base class member.
41. Unlike constructors, a derived class destructor is not responsible for revoking the members of a base class object, and the compiler always explicitly calls the destructor of the base-class part of the derived class object. Each destructor is only responsible for the clarity of its own members.
42. Even if there is no work to do. The root class of the inheritance hierarchy should also define a virtual destructor.
43. In copy control, only destructors can be defined as virtual functions, and constructors cannot be defined as virtual functions. Constructors are executed before the object is completely constructed. When the constructor executes, the object's dynamic type is incomplete. Defining an assignment operator as a virtual function defines a operator= in a derived class as a base class object that does not conform to the assignment operator in the derived class. Therefore, it is confusing and useless to define the class's assignment operator as a virtual function.
44. Assume that a virtual function is called in a constructor or destructor. The version number that defines the type for the constructor or destructor itself is executed.
45. In the case of inheritance, the scope of the derived class is nested within the scope of the base class.
46. The static type of an object, reference, or pointer determines the behavior that an object can complete. Even when static types and dynamic types may be different. Just as a reference or pointer to a base class type can occur, a static type still determines what members can be used.
47. A derived class member function in a derived class scope will mask the base class member. Base class members are masked even if the function prototype is different.
48. Assuming that a derived class wants to use all overloaded version numbers with its own type, the derived class must either redefine all overloaded version numbers or not redefine them.
If you do not want to redefine all, you can provide a using declaration for overloaded members. A using declaration can only specify a name. You cannot specify a table of parameters. It is therefore possible to add all overloaded instances of the function to the scope of the derived class.
49. Virtual functions must have the same prototype in both the base class and the derived class.
50.c++ Primer P501. A function with the same name as a derived class may mask the virtual function of the base class. It cannot be called through a derived class object, and can be called by a base class reference or pointer to a derived class object.
51. The derived class object is "cut off" when it is assigned to the base class object. So containers are not very well fused with inheritance-related types.
52. The polymorphism that object-oriented programming relies on is known as execution-time polymorphism. The polymorphism that generic programming relies on is called compile-time polymorphism or parameter polymorphism.
53. The name used as a template parameter cannot be reused within the template, which also means that the name of the template can only be used once in the same template.
54. Prefix the template member name with Keywordtypename to tell the compiler to treat the member as a type.
55. Array-shaped to declare references to arrays. Assuming that the shape is a reference to an array, the compiler does not convert the array's actual arguments into pointers, but rather passes the array's reference itself. In such a case, the size of the array becomes part of the form and the actual participation type. The compiler checks to see if the size of the array's actual participation matches the size of the shape.
56. Explicit template implementation matches the corresponding template shape from left to right.
57. When the compiler sees the template definition, it does not immediately generate code. Only when you see the template is used. The compiler produces a specific type of template instance when a function template is called or an object of the class template is called.
58. In the include compilation model. The compiler must see the definition of all the templates used.
59. A non-type template argument must be a compile-time-constant expression.
60. Special and partial specificity (partial) can have a completely different set of members than the generic class template.
61. Function templates can be overloaded: ability to define multiple function templates with the same name but with different number of shapes or types. You can also define generic non-template functions that have the same name as the function template.
62. The exception object is created by copying the result of the thrown expression, which must be a type that can be copied.
63. Throwing pointers is generally a bad idea: throwing a pointer requires the object to exist in a random place where the corresponding processing code exists.
64. During stack unwinding, the memory used by the local object is freed and the destructor for the class type local object is executed.
65. When a stack is expanded for an exception, the destructor assumes that it throws its own unhandled and an exception, which will cause the standard library terminate function to be called. In general, the Terminate function calls the Abort function to force an abnormal exit from the entire program.
66. Unlike destructors, what is done inside the constructor often throws an exception, so make sure to revoke the constructed member appropriately.
67. Assuming no matching catch is found, the program calls the library function terminate.
The type of 68.catch capture must be defined, and the type's forward declaration does not work.
69. In general, suppose that the catch clause deals with an exception of a type that is related to inheritance, it should define its own shape as a reference.
70. Assume catch (...) Used in conjunction with other catch clauses. It must be the last one. Otherwise. Whatever catch clause is behind it, it will not be matched.
71. Constructors to handle exceptions from constructor initialization, the only way to do this is to write the constructor as a function test block.
72. Abnormal security means that even if an abnormal program can operate normally, the assigned resources are released appropriately. By defining a class to encapsulate the allocation and release of resources, the resources are guaranteed to be freed. This technique is often referred to as "resource allocation as initialization", or RAII.
You should design a resource management class. So that the constructor allocates resources and the destructor frees the resources.
The 73.autoi_ptr can only be used to manage an object returned from new. It cannot manage dynamically allocated arrays.
When auto_ptr is copied or assigned, there is an unusual behavior, so auto_ptr cannot be stored in the standard library container type. The copy and assignment of the auto_ptr changes the right operand, so that the left-and left-hand operand of the assignment must be a modified lvalue.
74. You should only ask the Auto_ptr object with get or use the returned pointer value. You cannot use get as an argument to create other auto_ptr objects.
Another difference between a 75.auto_ptr object and a built-in pointer is that you cannot assign an address 9 or other pointer directly to the AUTO_PTR object
76.auto_ptr defects:
77. Assume that a function declaration does not specify an exception description. The function can throw an arbitrary type of exception.
78. At compile time, the compiler cannot and will not attempt to verify the exception description. Assuming that the function throws an exception that is not listed in its exception description, the standard library function unexpected is called.
By default, the unexpected function calls the Terminate function, and the Terminate function usually terminates the program.
79. Because the exception description cannot be checked at compile time, the application of exception description is generally limited. An important case of the utility of exception description is. Assuming that the function guarantees that no exception is thrown, it can be helpful to both the user and compiler of the function.
80. A derived class virtual function exception description must be the same as the exception description of the corresponding base class virtual function, or more restrictive than the latter. This restriction guarantees that when a derived class virtual function is called with a pointer to a base class type, the derived class exception description does not add a new, thrown exception.
81. A pointer to the function with the exception description is initialized with a pointer. or assign the latter to the function address. The exception description for two pointers does not have to be the same. However, the exception description of the source pointer must be at least as strict as the target pointer.
82. Namespaces can be defined within global scope or other scopes. But cannot be defined inside a function or class.
Namespace scopes cannot end with semicolons.
83. Namespaces can be defined in several parts. A namespace is made up of the sum of its detached definition parts. namespaces are cumulative.
84. Unnamed namespaces are different from other namespaces. The definition of an unnamed namespace is local to a specific file and never spans multiple text files.
Before a namespace introduces C + +, a static declaration is used to name the file locally.
85. Assuming that the header file defines an unnamed namespace, in each file that includes the header, the names in that namespace define different local entities.
86. A function that accepts class-type (or class-type pointers and reference-parameters), and functions that are defined in the same namespace as the class itself (including overloaded operators), are visible when using class-Type objects (or class-type references and pointers) as the actual participation.
87. To provide its own specificity for the template defined in the namespace. You must ensure that you define the specificity in the namespace that includes the original template definition.
88. In a virtual derivation, the virtual base class is initialized by the constructor of the bottommost derived class. Regardless of where the virtual base class is present in the inheritance hierarchy, the virtual base class is always constructed before the non-virtual base class is constructed.
89.sort, sort_heap Sort by default using less. To increment the sort. The make_heap default uses less, which is the maximum heap. Big in front, small in the rear.
90. A template function is an instance of a function template.
91. Functions cannot be biased.
92. Unless I have a good reason to agree that constructors are used for implicit type conversions. Otherwise I will declare him as explicit.
93.
Widget W2 = W1; Call the copy constructor, not the copy assignment operator
Generics and object-oriented C + +