/*copyright (c) 2016, *all Rights reserved, School of computer and Control engineering, Yantai University. * File name: My.cpp * Creator: Businessman * Completion date: May 6, 2016 * * Problem Description: Read the program, write out the results of the program and understand its operating mechanism. */#include <iostream> #include <cstring>using namespace Std;class a{ char *a; Public: A (a &t); A (char *aa) { a=new char[strlen (aa) +1];//The significance of this is that the memory space can be dynamically allocated, according to actual needs, more efficient use of memory; strcpy (A,AA);// Data member a relates to the form parameter AA: AA is a parameter, returns a value according to the length of AA, +1 is the ending character, and then a string of AA is copied to a. } ~a () { delete[]a;//when the main function ends, the destructor is performed, freeing previously dynamically allocated memory. } void output () {cout<<a<<endl;}}; A::a (A &t) {a=new Char[strlen (T.A) +1];//The significance of this is: can dynamically allocate memory space, according to actual needs, more efficient use of memory; strcpy (A,T.A);} int main () { A A ("Good monring, Code monkeys!"); A.output (); A B (a); B.output (); return 0;}
Week Nineth-Program Reading