#include<iostream> using namespace std; class time { public: int hour; int m; int s; time(int a,int b,int c):hour(a),m(b),s(c){} }; void show(time p) { p.hour=2; } int main() { void show(time e); time x(8,5,6); show(x);///并不会改变x.hour的值,因为只是值传递,并不是&地址传递 cout<<x.hour<<endl; return 0; }
结果: