首页 > 编程语言 > 详细

【c++程序】引用和重载

时间:2015-04-17 18:23:58      阅读:150      评论:0      收藏:0      [点我收藏+]
#include<iostream>
using namespace std;
#include<string>
void JiaoHuan(int *a,int *b)
{
	int t=*a;*a=*b;*b=t;
}
void JiaoHuan(int &a,int &b)
{
	int t=a;a=b;b=t;
}
void print(int& n)
{
	cout<<&n<<'\t'<<hex<<showbase<<n<<endl;
}
struct Window{
	string text;
	int x,y;
	int width,height;
};
void input(Window &r)
{
	cout<<"请输入窗口的标题、xy坐标、宽度和高度"<<endl;
	cin>>r.text>>r.x>>r.y>>r.width>>r.height;
	//return w;
}
void print(const Window &r)
{
	cout<<"======="<<r.text<<"======"<<endl;
	cout<<"从("<<r.x<<','<<r.y<<")到("<<r.x+r.width<<','<<r.y+r.height<<")"<<endl;
}
int main()
{
	Window w;
	input(w);
	print(w);
	int n=10;
	int m=20;
	JiaoHuan(&n,&m);//函数的重载
	cout<<"n="<<n<<"m="<<m<<endl;
	JiaoHuan(n,m);
	cout<<"n="<<n<<"m="<<m<<endl;
	void(*p)(int&,int&)=&JiaoHuan;
	p(n,m);
	cout<<"n="<<n<<"m="<<m<<endl;
	cout<<"&n="<<&n<<"&m="<<&m<<endl;
	print(m);
	print(n);
	/*int i;
	for(i=0;i<5;i++)//i仅在for()中有效
		cout<<i<<endl;
	cout<<i<<endl;//输出5*/
    return 0;
}

【c++程序】引用和重载

原文:http://blog.csdn.net/u012503639/article/details/45097851

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!