由于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