哪位大哥帮我解释一下这个程序的先后执行顺序,我我序号都表再每一块的前面(冒号前面的数字)您只需排序

[复制链接]
查看11 | 回复2 | 2010-9-1 09:19:02 | 显示全部楼层 |阅读模式
#include //妈的,有问题找不出来;
using namespace std;
class point
{
private:

int xpos;

int ypos;
public:
1:point(int x=0,int y=0)

{

cout<<"点的构造函数被执行"<<endl;

xpos=x;

ypos=y;

}

2:point(const point& pt)

{

cout<<"点的复制构造函数被执行"<<endl;

xpos=pt.xpos;

ypos=pt.ypos;

}

3:void print()

{

cout<<"("<<xpos<<","<<ypos<<")"<<endl;

}
};
class line
{
private:

point pt1;

point pt2;
public:
4: line(int x1,int y1,int x2,int y2):pt1(x1,y1),pt2(x2,y2)

{

cout<<"线的构造函数被执行"<<endl;

}
5:line(const line &11):pt1(11.pt1),pt2(11.pt2)

{

cout<<"线的复制构造函数被执行"<<endl;

}
6: void draw()

{

pt1.print();

cout<<" to ";

pt2.print();

cout<<endl;

}
};
int main()
{
7:line 11(1,2,3,4);
8:11.draw();
9:line 12(11);
10:12.draw();
11:return 0;
}

回复

使用道具 举报

千问 | 2010-9-1 09:19:02 | 显示全部楼层
哥们,变量好像不能以数字开头吧,你那几个变量都是数字11,而不是字母ll第4、7、8、9、10都有问题,改过来之后就没事了。下面是运行结果:点的构造函数被执行点的构造函数被执行线的构造函数被执行(1,2) to (3,4)点的复制构造函数被执行点的复制构造函数被执行线的复制构造函数被执行(1,2) to (3,4)另外,麻烦把注释写语句后面行吗,这样方便别人复制代码。。。
回复

使用道具 举报

千问 | 2010-9-1 09:19:02 | 显示全部楼层
求人不如求己拿个调试工具, 按上面设好断点, 然后调试一次不就一目了然了么
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行