Deep Exploration C + + object model notes (1)--new and delete operators

Source: Internet
Author: User

int New int (5);

The new operation is actually made up of two steps:

(1) Configure the required memory with the appropriate new operator function entity.

Call the new operator in the function library.

int New sizeof int ) );

(2) Set an initial value for the configured object.

5;

Initialization should be performed only after the memory configuration succeeds (via the new operator).

1 int *pi; 2 3 if sizeof (int))) 4 5 5 // In two steps

In a similar way;

Delete Pi; if 0 ) __delete (pi);

Note that pi is not automatically cleared 0 (NULL).

So if you have the following actions:

if 5 ( ) {  //...}

will be legal (but unpredictable).

Delete Ends the life of the object that the pi points to, so it should not be processed later.

When new is working on a class:

New Point3D;

is converted to:

Point3D *origin; // Pseudo Code if sizeof  = Point3D::P Oint3d (Origin);

Deep Exploration C + + object model notes (1)--new and delete operators

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.