#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
![](https://img2024.cnblogs.com/blog/35695/202407/35695-20240713070336838-1837943664.jpg)