Class and object

xiaoxiao2021-03-06  80

Class and object a data object is a special case of a data type; the same, a class object is a special case for a certain type. Comparison between the concept of class concepts and data types: The data type is just the implementation / use of the data, which is a passive object, operates by the operator - function; the class is the data structure and it is closely related. The package of operation function (also known as method) is an active object, triggered by message. Class interface definition: Class class type {private: private member declaration; public: public member statement;}; public member is the information interface of the object of the class, can only be accessed by functionality in the class scope -> Scope specific finger where? Member function is also known, is the information interface, class objects pass the private member in the class. -> The implementation of the class interface For a class that has been used, you can modify the behavior of such objects by adding new member functions. It is set to create an object next to it. The format is a class name object name; such as Person ZH; how to operate one member in the object? We use a dot "." Reference an object member: such as: zh.Name Note: After generating an object, the system is object and only assigns storage space for objects. How to understand the constructor? Constructor (a special member function) brighter the members of the members and classes, namely providing glue function? It initializes the object. To understand the role of constructor, you must first understand the difference between initialization and assignment, which is the memory unit that directly fills the object when the object is created, so there is no intermediate process such as data type conversion, which will not generate temporary Objects; assignment is the function that can be called after the object is created and can be called multiple times, since it calls the "=" operator, it may need to perform type conversion, which will generate temporary objects. So, we can think that when the memory is allocated, it becomes a good available state from the original state. Another important purpose for constructuring is to give some opportunities that may exist in creating an initialization, otherwise the virtual mechanism cannot be guaranteed. ?

To turn off the lights, you must continue to learn about the constructor. Reference book: High Quality Procedure Design Guide - C / C Language BlueRainzzb2008@hotmail.com

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

New Post(0)