我在学习李龙澍主编的C++程序设计第5章第13例时程序出错,代码是这样的:
#include <iostream.h>
#include <string.h>
class String{
char str[32];
public:
String() {str[0]='\0';}
String(char *){strcpy(str,s);}
String(String&){strcpy(str,s.str);}
String & operator=(String &);
String & operator=(char *);
void display(){cout<<str<<endl;}
};
String&String::operator=(String & s)
{if(this==&s) return*this;
strcpy(str,s.str);
return *this;
}
String&String::operator=(char*s)
{
strcpy(str,s);
return *this;}
void main()
{
String s1;
cout<<"开始的s1:";
s1.display();
s1="C++是最好的计算机语言!";
cout<<"用字符串赋值后的s1:";
s1.display();
String s2("面向对象程序设计真棒!");
cout<<"开始的s2:";
s2.display();
s2=s1;
cout<<"用s1去赋值后的s2:";
s2.display();
}
E:\C++文件\C++5_13.CPP(8) : error C2065: 's' : undeclared identifier
E:\C++文件\C++5_13.CPP(9) : error C2228: left of '.str' must have class/struct/union type
总是提示上面2处错误,没想到教科书中出错,还请各位高手指点.(刚刚自学C++)