如果你也是这个问题的话那么就不是因为中文和英文VC的区别,而是vc6的bug,你把sp6 for vc6.0的补丁装上应该没事了
最后,申明一下,如果你的编译器编译代码出了问题,你想要别人帮你解答的话应该把你看到的出错信息贴出来,否则别人不好下手帮你解决,因为问题都不知道是什么作者: 轌婲の滿天飛 时间: 2009-11-3 03:31
看了半天,郁闷半天
是个八哥....
郁闷
还好问了aogun怎么回事,要不我就疯了作者: 乄獨萊◇獨徍 时间: 2009-11-3 03:31
谢谢两位
下次我会注意的作者: 阳光aiq浪子 时间: 2009-11-3 03:31
s3=s1+s2; //line 95 here is error, no match for 'operator='作者: ══════ 时间: 2009-11-3 03:31
以下是引用kai在2006-6-30 9:53:50的发言:
s3=s1+s2; //line 95 here is error, no match for 'operator='
代码中已经重载了
void operator =(String& c1);//ok
String operator +(String& c2);//ok
friend istream& operator >>(istream &cin,String &o1);//ok
friend ostream& operator <<(ostream &cout,String &o2);//ok作者: 爱随缘 时间: 2009-11-3 03:31
it is depend on which compiler you uesed. When you use gcc, you will get error.
strictly speaking, you should define your copy constructor and assignment function in this form
Classname(const Classname & object); // copy constructor
// pay attention to "const", you should not forget this keyword
Classname & operator=(const Classname & object); // assignment
// pay attention to "const", you should not forget this keyword
I have his class rewritten, take a look.
程序代码:
#include <iostream>
using namespace std;
class String
{
public:
String()
{
inside= new char[50];
inside[49] = '\0';
}
String(const char * get)
{
int length = strlen(get);
inside = new char[length + 1];
strcpy(inside, get);
inside[length] = '\0';
}
String(const String & s1) // this is a copy constructor,
// it must defined it with using keyword "const",
// when you write your code strictly.
// with keyword const to
// tell your compiler,
// this parameter will be just used but not changed.
{
int size = strlen(s1.inside) + 1;
inside = new char[size];
strcpy(inside, s1.inside);
inside[size-1] = '\0';
}//ok
int find(String & s2);
int length();//ok
cout<<s3<<endl;
for(int i=0;i<s3.length();i++)
cout<<s3[i];
cout<<endl;
if(s1>s2)
cout<<s1<<" is more lager than "<<s2<<endl;
cout<<s3.find(s2);
return 0;
}作者: ﹎想埝祢⿰ 时间: 2009-11-3 03:31
谢谢kai的讲解
可是我还是有点不明白
你在上面的构造函数里面
String(const String & s1) // this is a copy constructor,
// it must defined it with using keyword "const",
// when you write your code strictly.
// with keyword const to
// tell your compiler,
// this parameter will be just used but not changed.
上面的红色部分我不明白
就算我没告诉它这个是CONST的
只要下面没有错误的使用应该也不会出错才对
我用的是VC++6.0作者: 释放压力 时间: 2009-11-3 03:31
you should know the meaning of const and you should know what is standard in C/C++作者: →莲佳 时间: 2009-11-3 03:31
谢谢kai