对象的常引用
1 #include <iostream> 2 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */ 4 using namespace std; 5 class Time 6 { 7 public: 8 Time(int,int,int); 9 int hour; 10 int minute; 11 int sec; 12 }; 13 14 Time::Time(int h,int m,int s) 15 { 16 hour=h; 17 minute=m; 18 sec=s; 19 } 20 21 void fun(Time &t) 22 { 23 t.hour=18; 24 } 25 26 int main(int argc, char** argv) { 27 28 Time t1(10,13,56); 29 fun(t1); 30 cout<<t1.hour<<endl; 31 cout<<t1.minute<<endl; 32 return 0; 33 }