#include <iostream>
using namespace std;
class aClass {
public:
aClass(int n) { i = n; }
void set(int n) { i = n; }
int get() { return i; }
private:
int i;
};
void Sqr(aClass ob)
{
ob.set(ob.get() * ob.get());
cout << "copy of obj has i valve of ";
cout << ob.get() << "\n" << endl;
}
int main()
{
aClass obj(10);
Sqr(obj);
cout << "But,obj.i is unchanged in main" << endl;
cout << obj.get();
return 0;
}
c++使用对象作为函数参数
最新推荐文章于 2024-07-11 13:30:38 发布