#include
using namespace std;
class A
{
public :
A(){x=0;y=0;}
A(int i,int j)
{
x=i;y=j;
}
void SetValue(int i,int j)
{
x=i;y=j;
}
void Disp()
{
cout<<x<<","<<y<<endl;
}
private:
int x,y;
};
void fun(A &r) //对象引用作形参
{
r.SetValue(10, 20);
}
int main(int argc, const char * argv[]) {
A a(1,2);
fun(a);
a.Disp();
return 0;
}
输出:
10,20
Program ended with exit code: 0
c++中对象的引用作为函数的参数
最新推荐文章于 2024-05-09 22:02:15 发布