| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 465 人关注过本帖
标题:怎样解释这个结果?
取消只看楼主 加入收藏
cz522321
Rank: 1
等 级:禁止访问
威 望:2
帖 子:569
专家分:5
注 册:2006-3-13
结帖率:100%
收藏
 问题点数:0 回复次数:0 
怎样解释这个结果?

文件1:"tpointer.h"
class TPoint
{
public:
TPoint(int x,int y){X=x;Y=y;}
TPoint(TPoint &p);
~TPoint(){cout<<"Destructer called!\n";}
int Xcoord(){return X;}
int Ycoord(){return Y;}
private:
int X,Y;
};
TPoint::TPoint(TPoint &p)
{ X=p.X;
Y=p.Y;
cout<<"copy_initialization Constructer called!\n";
}
文件2:
#include<iostream.h>
#include"tpointer.h"
TPoint f(TPoint Q);
void main()
{
TPoint M(20,35),P(0,0);
TPoint N(M);
P=f(N);
cout<<"P="<<P.Xcoord()<<","<<P.Ycoord()<<endl;
}

TPoint f(TPoint Q)
{
cout<<"ok\n";
int x,y;
x=Q.Xcoord()+10;
y=Q.Ycoord()+20;
TPoint R(x,y);
return R;
}
结果为:
copy_initialization Constructer called!
copy_initialization Constructer called!
ok
copy_initialization Constructer called!
Destructer called!
Destructer called!
Destructer called!
P=30,55
Destructer called!
Destructer called!
Destructer called!
Press any key to continue
把文件2的6行和8行改为:
6行:TPoint M(20,35);
8行:TPoint P=f(N);
之后结果为:
copy_initialization Constructer called!
copy_initialization Constructer called!
ok
copy_initialization Constructer called!
Destructer called!
Destructer called!
P=30,55
Destructer called!
Destructer called!
Destructer called!
Press any key to continue
请解释一下这个结果的函数调用顺序问题?十分感激!

搜索更多相关主题的帖子: 结果 解释 
2006-07-18 12:32
快速回复:怎样解释这个结果?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015486 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved