标签:
#include<iostream> #include<cstring> using namespace std; class A { private: char *a; public: A(char *aa) { a = new char[strlen(aa)+1]; //(a)这样处理的意义在于:为aa指针开辟出空间 strcpy(a, aa); //(b)数据成员a与形式参数aa的关系:将a指针所指向地址复制给aa指针 } ~A() { delete []a; //(c)这样处理的意义在于: 释放空间 } void output() { cout<<a<<endl; } }; int main(){ A a("good morning, code monkeys!"); a.output(); A b("good afternoon, codes!"); b.output(); return 0; }
学习心得:
好好学习 天天向上
标签:
原文地址:http://blog.csdn.net/ljd939952281/article/details/44960029