|
- #include <iostream>
- #include <string>
- using namespace std;
- class CStudent
- {
- char* p_name;
- char sex;
- int id;
- int age;
- public:
- CStudent() {};
- CStudent(const char* t_name, char t_sex, int t_id, int t_age):sex(t_sex), id(t_id), age(t_age)
- {
- int len_p = strlen(t_name);
- p_name = new char[len_p + 1];
- memset(p_name, 0, len_p);
- strcpy(p_name, t_name);
- }
- ~CStudent()
- {
- cout << "Student " << *p_name << "\t has been deleted!" << endl;
- if (p_name!= NULL)
- {
- delete[]p_name;
- p_name = NULL;
- }
- }
- };
- void test()
- {
- CStudent stud_1("zhangsan", 'f', 1001, 20);
- CStudent stud_2;
- stud_2 = stud_1;
- }
- int main()
- {
- test();
- return 0;
- }
复制代码 |
上一篇: 分享,学习历程,求大家在编程思路上多指导。。。下一篇: mfc 非模态窗口
|