标签:c++
#include<iostream> #include<string.h> using namespace std; class String_date { private: char * str; public: String_date(char * str); ~String_date(); char* get_infor() {return str;} }; String_date::String_date(char* s) { cout<<"constructing:"<<endl; str = new char [strlen(s) + 1]; strcpy(str,s); } String_date::~String_date() { delete str; cout<<"destructing:"<<str<<endl;//只要在析构函数中加入有效的打印语句就可以辨别 } int main() { String_date str1("teacher"); String_date str2("student"); cout<<str1.get_infor()<<endl; return 0; }
运行结果:
标签:c++
原文地址:http://blog.csdn.net/cherry_ermao/article/details/44699829