error C2600: "Ss::operator =": 不能定义编译器生成的特殊成员函数(必须首先在类中声明)
#include<iostream>#include<string>usingnamespacestd;classSs{char*ptr;public:Ss(char*s...
#include <iostream>
#include <string>
using namespace std;
class Ss{
char *ptr;
public:
Ss(char * s)
{ ptr=new char[strlen(s)+1];
strcpy_s(ptr,8,s);
}
~Ss( ) { delete ptr; }
Ss & operator=(const string & );
void print( ) { cout<<ptr<<endl; }
};
Ss & Ss::operator=(const Ss &s )
{
if(this==&s) return *this;
delete ptr; ptr=new char[strlen(s.ptr)+1];
strcpy(ptr,s.ptr); return *this;
}
void main(){
Ss p1("Hello");
{
Ss p2("chong qing");
p2=p1;
cout<<"p2:";
p2.print();
}
cout<<"p1:";
p1.print();
}
我是用VC2010编译的 展开
#include <string>
using namespace std;
class Ss{
char *ptr;
public:
Ss(char * s)
{ ptr=new char[strlen(s)+1];
strcpy_s(ptr,8,s);
}
~Ss( ) { delete ptr; }
Ss & operator=(const string & );
void print( ) { cout<<ptr<<endl; }
};
Ss & Ss::operator=(const Ss &s )
{
if(this==&s) return *this;
delete ptr; ptr=new char[strlen(s.ptr)+1];
strcpy(ptr,s.ptr); return *this;
}
void main(){
Ss p1("Hello");
{
Ss p2("chong qing");
p2=p1;
cout<<"p2:";
p2.print();
}
cout<<"p1:";
p1.print();
}
我是用VC2010编译的 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询