【项目1-深复制体验】
(1)阅读下面的程序,补足未完成的注释
#include<iostream> #include<cstring> using namespace std; class A { private: char *a; public: A(char *aa) { a = new char[strlen(aa)+1]; //(a)这样处理的意义在于:_________杜绝野指针__________________ strcpy(a, aa); //(b)数据成员a与形式参数aa的关系:________把aa赋值于a______________________ } ~A() { delete []a; //(c)这样处理的意义在于: ____________节省空间,删除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; }
时间: 2024-10-12 21:35:42