#include <iostream>using namespace std;class mstring {public: mstring(const char* str) { length = strlen(str); m_char = new char(length + 1); strcpy_s(m_char, length + 1, const_cast<char*>(str)); } friend ostream& operator<<(ostream& out,const mstring& str) { if (NULL != str.m_char) { out << str.m_char; return out; } } ~mstring() { if (m_char != NULL) { delete m_char; length = 0; } } char* m_char; int length; };int main(){ mstring* mstr = new mstring("Hello World!"); cout << mstr; return 0; }`
为什么内存会出错???
心有法竹
开心每一天1111
相关分类