// 这是一个关于赋值运算符重载的代码#include<iostream>#include<iostream>using namespace std;class String{private: char *str;public: String(char *s ="") { unsigned int length = strlen(s); str = new char[length + 1]; strcpy(str, s); } ~String() { delete[] str; } String& String::operator=(String &s) { if (this != &s) { delete[] str; unsigned int length = strlen(s.str); str = new char[length + 1]; strcpy_s(str,s.str); } return (*this); } void display() { cout << str << endl; }};int main(){ String s1 = "Welcome to my world"; s1 = s1; cout << "自赋值结果: "; s1.display(); String s2; s2 = s1; cout << "s2 = s1" << endl; cout << "s1 : "; s1.display(); cout << "s2 : "; s2.display(); return 0;}截图是QT4.7报告了代码出错。VS2017可以运行,但是执行出“自赋值结果:Welcome to my world”后就停止并强退书上的运行结果是:自赋值结果:Welcome to my worlds2 = s1s1:Welcome to my worlds2:Welcome to my world