刚学C++,自己写了个简单的mystring,有警告存在啊,const怎样用呢
#include <iostream>#include <cstring>//#include "Integer.h"using namespace std;class mystring {private: char* _s;public: mystring(int a){ _s = new char[a+1]; for(int i = 0; i < a; i++) _s[i] = ' '; _s[a+1] = '\0'; } /*21*/mystring( char* s ) { _s = new char[strlen(s)+1]; _s = s; } mystring( ) { _s = new char[1]; _s[0] = '\0'; } ~mystring() { delete []_s; } void display() { cout<<"<"<<_s<<">"<<endl; }};int main(){ mystring s1("sdfgfdgdf"); mystring s2(5); mystring s3; s1.display(); s2.display(); s3.display(); s3 = s1; s3.display(); return 0;}