STL string 析構異常原因分析
阿新 • • 發佈:2019-02-15
class __declspec(dllexport) smart_string { public: smart_string(); ~smart_string(); constchar*get_data() const; void set_data(constchar*data); void clear(); smart_string &operator+= (constchar*data); private: std::string*data; }; smart_string::smart_string() { data =new std::string(); } smart_string:: ~smart_string() { if (data) { data->clear(); delete data; } } constchar* smart_string::get_data() const { return data->c_str(); } void smart_string::set_data(constchar*_data) { data->clear(); data->replace(0, data->size(), _data); } void smart_string::clear() { data->clear(); } smart_string & smart_string::operator+= (constchar*_data) { *data += _data; return*this; }