您的位置:首页 > 其它

对象的引用的变形——&t->*t

2013-04-27 18:24 99 查看
#include <iostream>
using namespace std;
class Time
{
public:
Time(int,int,int);
int hour;
int minute;
int sec;
};

Time::Time(int h,int m,int s)
{
hour=h;
minute=m;
sec=s;
}

void fun(Time *t)//形参t是Time类对象的引用
{
(*t).hour=18;
}

int main()
{
Time t1(10,13,56);
fun (&t1);//实参是Time类对象,可以通过引用来修改实参t1的值;t1传的是地址
cout<<t1.hour<<" "<<t1.minute<<" "<<t1.sec<<endl;//输出的t1.hour为18
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐