#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;
}
对象的引用的变形——&t->*t
最新推荐文章于 2024-06-02 19:12:34 发布