|
#include <iostream>
#include <string>
using namespace std;
class String
{
private:
string s;
public:
String(string s1)
{
s=s1;
}
String()
{
}
~String()
{
}
void show()
{
cout<<s<<endl;
}
String operator+(String &);
friend void operator=(String &,String &);
friend int operator>(String &,String &);
};
String String::operator+(String &s1)
{
String t;
t.s=s1.s;
return t;
}
void operator=(String &s1,String &s2)
{
s1.s=s2.s;
}
int operator>(String &s1,String &s2)
{
if(s1.s>s2.s)
return 1;
else
return 0;
}
int main()
{
String str1("LOVE"),str2("you"),str3;
str1.show();
str2.show();
str3=str1+str2;
str3.show();
if(str1>str2)
cout<<"str1>str2"<<endl;
else
cout<<"str1<str2"<<endl;
getchar();
return 0;
}
出错:
32 D:\Dev-Cpp\未命名1.cpp
`void operator=(String&, String&)' must be a nonstatic member
47 D:\Dev-Cpp\未命名1.cpp
`void operator=(String&, String&)' must be a nonstatic member |
|