码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2015-04-17 18:25:15      阅读:158      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!