gogoWebsite

C++_new class

Updated to 2 days ago

Define a class:

//Class definition (NG -> OK):
 public class A : public class B {}

        class A : public B {};

Declare an object:

(1) Form of not manually applying for space:

//Create an object (NG -> OK):
 class A a;
       A a;

(2) Manual application space form:

//Create an object:
 A *a = new A();
 delete a;

(1) Use stack space, system management, and after exiting the scope, the space is released by the system;

(2) Use heap space and program management, and you need to call delete() to release it, otherwise, memory leaks;

Can be compared to C languageNormal variablesand mallocPointer variable