#include <iostream> #include <cstring>using namespace Std;class a{private: char *a;public: A (char *AA) { a = new Char[strlen (AA) +1]; //
strcpy (A, AA); //
} ~a () { delete []a; //
} void Output () { cout<<a<<endl; }}; int main () { A A ("Good Morning, Code monkeys!"); A.output (); A B ("Good Afternoon, codes!"); B.output (); return 0;}
(3) To add a copy constructor for Class A, test with the following main function
int main () { A A ("Good Morning, Code monkeys!"); A.output (); A B (a); B.output (); return 0;}
#include <iostream> #include <cstring>using namespace Std;class a{private: char *a;public: A (char *AA) { a = new Char[strlen (AA) +1]; strcpy (A,AA); } A (a &b) { a = new Char[strlen (B.A) +1]; strcpy (A,B.A); } ~a () { delete []a; } void output () { cout<<a<<endl; }}; int main () { A A ("Good Morning, Code monkeys!"); A.output (); A B (a); B.output (); return 0;}
Item 1-Deep copy experience (3)