由於x_str,y_str是局部的,所以我沒有在這個函數中得到正確的輸出。 (非法字符打印在x_str和y_str的地方) 我不想將2個更多的成員變量x_str,y_str添加到我的類中。如何打印位置
因此,什麼可能是取代這個功能,以獲得正確的輸出。
string Pos::getPosReport(){
string x_str;
x_str = x;
string y_str;
y_str = y;
return string("(" + x_str + "," + y_str + ")");
}
編輯:
class Pos {
int x;
int y;
public:
Pos();
Pos(Pos const&);
Pos(int,int);
Pos& operator=(Pos const&);
bool operator==(Pos const&);
bool operator!=(Pos const&);
void setPos(Pos const&);
void setPos(int,int);
void setx(int);
void sety(int);
int getx() const ;
int gety() const ;
string getPosReport();
virtual ~Pos();
};
問題不明確。你需要解決什麼問題? – 2012-02-02 14:26:08
誰是x和y? – 2012-02-02 14:26:21