#include<iostream>
#include<stdlib.h>
using namespace std;
class A
{private:
char *a;
public:
A():a(NULL){
} //(1)__初始化_______________________________________
A(char *aa) {
a=new char[strlen(aa)+1]; //(2)______动态确定_a的空间____________________________________
strcpy(a,aa); //(3)______把aa复制给a______________________________________
}
~A() {
delete []a;
} //(4)_____________析构函数释放a的空间______________________________
void output(){
cout<<a<<endl;
}
};
int main()
{
A a("good morning, code monkeys!");
a.output();
return 0;
}
读程序的完善
最新推荐文章于 2022-07-28 18:33:12 发布