Call of sdut 3-3 Constructor (advanced), sdut3-3
3-3 calling Constructor (advanced) Time Limit: 1000 MS Memory limit: 65536 K Description
Through this exercise, you can learn the time to call constructor and destructor when creating common objects, object arrays, and dynamic creation and destructor;
A Class A must be created. The class only contains constructor and destructor. The class definition and main code of the main function are written according to the program output.
Input
None
Output
The output contains 11 rows of data, as shown in the sample output.
Sample Input
None
Sample output
----begin main---constructing an object of Aconstructing an object of ADestructing an object of A*******constructing an object of Aconstructing an object of A----end main---Destructing an object of ADestructing an object of ADestructing an object of A
Sample program from Huang Jingjing
# Include <iostream> using namespace std; class A {public: A () // constructor {cout <"constructing an object of A" <endl ;}~ A () // destructor {cout <"Destructing an object of A" <endl ;}}; int main () {cout <"---- begin main ---" <endl; A a; A * B; // defines A pointer variable B = new A pointing to A class object; // delete B is the initial address of the new object in B; // release the memory space cout pointed to by B <"********" <endl; A c; A d; cout <"---- end main ---" <endl; return 0 ;}