) 的error及错误的指针
输入了书上练习题答案的代码:#include <string>
#include <iostream>
using namespace std;
class screen{
public :
typedef string ::size_type index;
char get() const{ return contents[ cursor];}
inline char get(index ht,index wd) const;
index get_cursor() const;
screen(index hght, index wdth,const string & cntnts);
screen& set (char);
screen& move (index r,index c);
screen& display(ostream & os);
private :
string contents;
index cursor;
index height;
index width;
};
screen ::screen(index hght, index wdth,const string &cntnts):
contents (cntnts),cursor(0),height(hght),width(wdth){}
char screen:: get (index r,index c)const
{
index row=r*width;
return contents[row+c];
}
inline screen::index screen ::get_cursor() const
{
return cursor;
}
screen &screen ::set(char c)
{
contents[cursor]=c;
return *this;
}
screen &screen:: move(index r,index c)
{
index row=r* width;
cursor=row+c;
return *this;
}
screen& screen::display(ostream &os)
{
os<<contents;
return *this;
}
int main(){
int a,b,d,e;
string c;
cin>>a>>b>>d>>e>>c;
screen myscreen(a,b,c);
myscreen.move(d,e).set('#').display(cout);
return 0;
}
1.zip
(62.59 KB)
问题截图:见附件文档 谢谢