Essential C ++

xiaoxiao2021-03-06  39

1. Local static object - heap object? 2. Default parameters - 1. Only define once, (header file or CPP file). 2. The resolution of the default value begins with the top right. Means Void Fun (int A = 0, INT B, INT C = 2) is incorrect 3. Overload VS TemplateOverLoad - multiple implementation template - the main body constant, data type change Template definition template Fun (Const Vector & VEC) {for (INT i = 0; i * Fibon_Seq (int size) function pointer defines E.GConst Vector * (* seq_ptr) (int)) BOOL SEQ_ELEM (INT POS, INT & ELEM, Const Vector * ( * SEQ_PTR) (int)) {const vector * pSEQ = SEQ_PTR (POS); // Call function pointer mode and normal function match IF (! PSEQ) // to check the initial value of the function pointer Can be 0const vector * (* seq_ptr) (int) = 0; can also be an address constor * (* seq_ptr) (int) = fibon_seq; 5. Inlineinline must be defined in header file. 6. IncludeInClude <*. H> - <> indicates the header file in the standard library "* .h" - "indicates the custom file 7. The array array is incorporated into the address of the first element. . Vector VS List vs DequeVector - Continuous memory stores Sequence Data. (Array) Random read efficiency High List - two-way linked tables Store Sequence Data. Insert delete efficiency high Deque - Similar to Vector, front, end insertion, delete efficiency, use to implement Queue. Direct [] can access serial container 9. Reference, pointer reference: always point to the first assignment . Quoted, the pointer is the same as the function parameter, the effect is the same: 1. Can be modified directly to the subject. 2. Do not copy the incoming object. The reference is copied is the address of the object, and the pointer is copied is the pointer itself.

Quote Before you win: References can avoid empty pointers (* PT) errors. When the pointer is led, first determine if the pointer is 0. Quote No need to judge this. IF (pt! = 0 && * pt == ...)

Avoid incurring tendencies, (will inertial selection when external calls, not pointers, reduce error opportunities for memory leaks)

9.1 Function parameter is the defined definition of public void fun (a & a) {a b (3); A = B; / / or this implementation // a * c = new a (3); // a = * C; / / delete a;} Using A A (5); fun (a); // Perform a = 3

9.2 Function parameter is a pointer public void fun (a * a) {a b (3); * a = b; // Using A * PA = New A (5); FUN (PA); / / Execute the PA content is 3 // ... Use Padelete Pa;

Java's function parameter passes and C default function parameter passes are all transmitted values. C also allows for reference. Any operation on the reference object is equivalent to the operation of the incoming object. Includes a new object. It is not possible in the function call in Java. Such as Void JavaFun (a a a) {a = new a ();} This is still the value when the Java function call is completed. But in C Void CPlusFun (A & A) {a b; A = B;} A After the function call is completed, the content has changed. 10. Stack Object VS Stack Object Stack Object (STACK), such as the object defined in the function, temporarily placed in the stack, the function is executed, and the contents in the stack are disposed. Pile Object (HEAP) - If the object is dynamically allocated, manage it by the programmer. 11. Function Object A Class object that is overloaded with Function Call: () is used to define an operator. Its role and function pointer are similar, but the function pointer is in the efficiency, so that the Call operator is inline. And keep the state (class object to save)

BIND2ND, BIND1ND is also function object, convert binary function object to a yuan, and another parameter is specified by the build function parameter of bing * nd.

12. The pointer of the pointer, the reference to the pointer to the change of the contents of the pointer only needs to pass the pointer. For the change in the pointer itself, the reference to the pointer or pointer is required. Chapter 4 Object-based programming styles 1. FORWARD DECLArations - Definition of the pointer or in this Class as a data type. It can be seen in compilation Similar to include, if the INCLUDE is nested, another class is declared. E.G Class Stack; 2.> The keyword inline is specified when the header file is defined or when the function is defined in the CPP file.

3. ConnStructors Default Constructors can provide default values ​​for each parameter. E.G class trigangular {triangular (int LEN = 1, int bp = 1) // is also default constructor. } Trigangular T = 8; // Calling only one parameter constructor rather than assignment operator 4. Member initialization list) MEMBER INITIZATION LIST followed behind the constructor parameter table colon, Separate with a comma, used to pass the parameters to the member variable. E.G Class Trigangular (const trigangular ": _ longth (rhs._length), _ next (rhs._next) {} member initial value table is better than assignment (when MEMBER OBJECT) principle?

5. Copy Constructor and Copy Assignment Operator Change the default member initialized behavior (Memberwise Initialization) Eg Trigangular T1 (8); Trigangular T2 = T1; the default T1's various member variables Assign each member variable to T2. If the class contains the member variable of the pointer, the default initialization causes the pointer of the two objects to the same address space, and the T1 is delayed, and the pointer of the pointer is released, and the pointer of T2 is still pointing to the block memory. Error! You should provide Copy Constructor Matrix :: Matrix (const Matrix & rhs): _ row (rhs._row), _ col (rhs._rol) {int Num = _row * _col; _pmat = new double (num); for (int i = 0; I

Using Boolean IS_ELEM = a :: IS_ELEM (IVAL); 9. Operator Reserved 9.1 Rule: 1. Does not introduce new operators 2. The four operators do not overload. * ::? 3. Operation cannot change 4 The priority cannot be changed 5. There must be a parameter in the parameter is a Class type.? 9.2 Define Member Function: int T_iterator :: Operator * () const {...}

Non-Member Function: Int Operator * (const t_iterator & r Hs) {....}

The operation operator of the Non-Member function is more than one parameter of the Member function, and the number of the left operand is represented by the MEMBER FUNCTION.

9.3 Front and rear pre-definition ( T) t_iterator & t_iterator :: Operator () { _ index; return * this;}

Back Definition (T ) T_Iterator T_Iterator :: Operator (int) {t_iterator teem = * this; _ index; return;} Because the overload specification must be the same, the C requires the post version has an int parameter and Front distinguish. The compiler will automatically generate an INT quotes (0) for the back function (0).

9.4 Function Object Reserved () Concept: Function Object is a class that provides function call implementations.

Declare and define class less {less (int val): _ val (val) {}; boolean operator () const {return value <_val;};

Using int count_less_than (const vector & vec, int COMP) {Less LT (Comp); int count = 0; for (INT i = 0; i

10. Pointer 10.1 define E.G Void (Classa :: * PM) (int); or type) (int); PTRTYPE PM = 0; PTRTYPE PM = 0;

10.2 Assignment PTRTYPE PM = & classa :: functiona;

10.3 Using Classa A; PTRTYPE PM = & Classa :: FunctionA; (a. * PM) (POS); // is equivalent to A.functionA (POS);

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

New Post(0)