oop object-oriented knowledge summary

The end of the period, to sum up the above teaching knowledge

 

Chapter nine

9.1 class declaration

1. The members of the class declaration to declare simultaneously access the properties of the member.

2.C ++ The only difference between the structure and the class: struct members access property defaults to the public , class members to access property defaults to Private .

3. General will have the external part of the design into open, you do not have external members of the design as a protected or private.

4. A class member functions for all data members of the same class have the ability to access unlimited.

9.2 The basic spatial objects

5. means creating objects memory space allocated to the object.

6. We will space the sum of non-static data members of the object called basic space occupied by the object.

9.3 Object of self-expression

7.this point is locked can not be changed.

8. const member function is a member of the class, the form of the implicit function of such parameters constant const pointer (the object of the present const * const the this ), it can only be read but can not modify any of the properties of this object function in vivo

9. const object can only call const member functions.

10. The class does not modify the object attributes among all member functions const member functions are designed to be beneficial.

 

9.5 class template with a template class

11. The function template is - at the source code level, and the pending data manipulation functions described type determined

Look at an example of a two-dimensional vector template:

template <typename TYPE> template class declaration class Vec2 // TYPE wherein the data type is determined, or as in the form of a data type

12. The template member function in the class declaration describes vitro when writing format:

template <typename TYPE> TYPE representation showing the template data type "template name <TYPE>" template full class name (with the form data type class name)

 

Chapter X constructor and assignment operator

1. constructors and destructors in a C ++ class with the object of creating, destroying the relevant function.

2. Perform assignment operation does not create a new object, as the left operand of assignment operator involved in the (left value object) is already existing objects, but may change the assignment operator operating data members only.

10.1 Constructors

3. constructor completes the processing target space, and configured to initialize the data structure members and so on.

4. no constructor can not construct the object.

5. Any type have at least two constructors (default constructor and default copy constructor)

6. The default constructor does not require a constructor arguments. When declaring class does not define any constructors if the system will provide a default constructor for the class.

7. conversion constructor: a constructor with arguments (constructor is called a conversion because you can use it to implement a data type of implicit conversion or cast) (I do not know what it means not to understand)

8. The use of a constructor

(1) to create an array of objects

  Creating an array of objects when there must be a constant as the number of elements in the array. Create each element of the array should be called once when the constructor or copy constructor.

  Format: the object class name array name [number of elements] = {constructor function name (argument list)};  

(2) creating a dynamic object or a dynamic array of objects

  C ++ new and delete operators have a strong function. When creating a new stack object with the operator, the operator having the operation function corresponding to the calling class constructor or a copy constructor.

  After the first address of the new operator to create an object heap (heap array of objects) succeeds, the return of the "cut" from the heap down the continuous space.

  Program with a pointer to the address value of the recording, the easy access to the operating element array stack object or stack, and the stack memory resources are released after the used application. If the new operation is unsuccessful, it returns a null pointer is NULL.

  You should call a constructor when creating each element of a dynamic array.

 

10.2 destructor

9. A destructor no return type, no parameters and can not be overloaded. (Function overloading usually using different parameter table is overloaded, but he can not be overloaded so no parameter) generally should not explicitly calling the destructor.

10. The class declaration time, if the system is not designed destructor will provide a default class destructor. The default destructor system only for cleanup Basic data space.

If the object with the resource, should be defined destructor for cleanup objects brought resources.

 

 

Guess you like

Origin www.cnblogs.com/joelovescoding/p/11829039.html