Examples of specific constructor procedure

When a new constructor specifically did what?

1. Create an empty object in memory;

2.this empty object point to the memory;

The key parameters defined and passed sequentially to the empty object is added to the key value;

4. Add at the end of the constructor statement return this, that is a pointer to the new object points to memory just created return out, pass-assigned to the variable.

 

Description:

1. Therefore, the constructor does is artificially added to the return statement, assuming a return statement is added, the added return this default will be blocked, can not be performed. That is to say: Although instantiated object has been created in memory, but there is no way to return the pointer to go out assigned to the variable;

2. The function of this arrow always points at the time of this definition, in the constructor, that is, the Hang Seng Index to a new object is created in memory, it does not matter who is going to perform with.

Guess you like

Origin www.cnblogs.com/zhangnan35/p/10954005.html