这个输出为什么不正确

sunshine_anycall 2010-11-05 05:39:39
// cpptest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

class Point
{
private:
int _x;
int _y;
public:

Point():_x(0),_y(0)
{}

int getX()
{
return _x;
}

int getY()
{
return _y;
}

void setX(int x)
{
_x = x;
}

void setY(int y)
{
_y = y;
}

void printPoint()
{
cout<<"x:" + _x <<endl;
cout<<"y:" + _y <<endl;
}
};

void setDefaultPoint(Point p,int x,int y)
{
p.setX(x);
p.setY(y);
}

void setDefaultPoint(Point& p,int x,int y,bool)
{
p.setX(x);
p.setY(y);
}

int _tmain(int argc, _TCHAR* argv[])
{
Point p;
Point* p1 = new Point();
setDefaultPoint(*p1,1,1,true);
p1->printPoint();

return 0;
}

==============
输出结果是



砸回事儿呢?
谢谢
...全文
89 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunshine_anycall 2010-11-05
  • 打赏
  • 举报
回复
Thanks you guys!
结贴给分
無_1024 2010-11-05
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ouyh12345 的回复:]
void printPoint()
{
cout<<"x:"<< _x <<endl;
cout<<"y:" <<_y <<endl;
}
[/Quote]
应该这样
dingshaofengbinbin 2010-11-05
  • 打赏
  • 举报
回复
void printPoint()
{
cout<<"x:"<<_x <<endl;
cout<<"y:"<<_y <<endl;
}
ouyh12345 2010-11-05
  • 打赏
  • 举报
回复
void printPoint()
{
cout<<"x:"<< _x <<endl;
cout<<"y:" <<_y <<endl;
}

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧