#include
class string
{
private:
char a[50];
public:
string();
string(char *m)
{
strcpy(a,m);
}
friend string operator+(string &cl1,string &cl2);
friend string operator-(string &cl1,string &cl2);
string& operator=(const string &cl1);
void display();
};
string operator+(string &cl1,string &cl2)
{
strcat(cl1.a,cl2.a);
return string(cl1.a);
}
string operator-(string &cl1,string &cl2)
{
int i=0;
for(;cl1.a[i]!='\0';i++)
{
if(cl1.a[i]==' ')break;
}
int j=0;
for(;cl2.a[j]!='\0';j++)
cl1.a[i+j]=cl2.a[j];
cl1.a[i+j+1]='\0';
return string(cl1.a);
}
string& string::operator=(const string &cl1)
{
char str[100];
strcpy(str,cl1.a);
return (*this);
}
void string::display()
{
cout<}
void main()
{
string s1("浙江大学 "),s3;
string s2("计算机学院欢迎您!");
s3=s1+s2;
s3.display();
s3=s1-s2;
s3.display();
}
程序编译没问题,但在运行时提示:
Linking...
40.obj : error LNK2001: unresolved external symbol "public: __thiscall string::string(void)" (??0string@@QAE@XZ)
Debug/40.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.
求高手解答。甚谢!