How is the object died?

zhaozj2021-02-16  70

After an object is constructed, the system constructs a post-array whether or not related to the compiler?

Today, the C language is reviewed, and a small program is composed. After discovering the object constructed, the system will call the sectic heatstroke yourself on the system yourself, and will not be called under DEV-C (using GCC)? Also, if it is created a pointer to an object, the system will not call the destructor yourself.

code show as below:

#include

Using namespace std;

Class counter {

PRIVATE: INT ELEM; PUBLIC: counter (); counter (int elem); ~ counter ();

Static int counter;

Counter :: counter () {elem = 0; counter ; cout << "in counter ()" <

Cout << "counter =" << Endl;

<

}

Counter :: counter (int Arg) {elem = arg; counter ; cout << "in counter (int) << Endl

Cout << "counter =" << Endl;

<

}

Counter :: ~ counter () {counter ---; cout << "in ~ counter ()" << endl;

Cout << "counter =" << Endl;

<

}

INT Main (int Argc, char * argv []) {counter C1; Counter C2; Counter C3; counter * cp = new counter (10); cp-> ~ counter (); return 0;}

The result of the operation under VC6 is:

In counter () counter () counter = 2in counter () counter = 3IN counter (int) counter = 4in ~ counter () counter = 3IN ~ counter () counter = 2in ~ counter () counter = 1in ~ counter ) counter = 0press any key to continue

In the DEV-C result:

In counter () counter () counter () counter = 2in counter () counter = 3IN Counter () counter = 4IN ~ counter () counter = 3press any key to payue..

==========================================================================================================================================================

in conclusion:

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

New Post(0)