3-2 calls to constructors Time limit:1000ms Memory limit:65536k Title Description
Through the practice of this topic, we can master the call of constructor function and destructor;
Create Class A; The class contains only constructors and destructors, and writes out the definition of the class and the code in main function main, according to the program's output.
Input
No
Output
The output data has 4 rows representing the calls to constructors and destructors, and this exercise requires the output of the program to be the same as the example.
Sample input
No
Sample output
Constructing an object of aconstructing an object of adestructing an object of adestructing an object of A
#include <iostream> #include <string>using namespace Std;class out{private:string s;public:out (String a) {s = A;} ~out () {cout<< "destructing an object of a" <<endl;cout<< "destructing an object of a" <<ENDL;} void display () {cout<<s<<endl;cout<<s<<endl;}}; int main () {out D ("Constructing an object of A"); D.display (); return 0;}
C + + constructors + destructors