第三周阅读程序 (4)

来源:互联网 发布:网络终端机密码 编辑:程序博客网 时间:2024/06/10 16:50

代码

#include <iostream>using namespace std;class Test{private:    int x,y;public:    void setX(int a)    {        x=a;    }    void setY(int b)    {        y=b;    }    void getXY(int &px, int &py) //引用    {        px=x;    //提取x,y值        py=y;    }};int main(){    Test p1,p2;    p1.setX(3);    p1.setY(5);    int a,b;    p1.getXY(a, b); //将 a=x, b=y    cout<<a<<'\t'<<b<<endl;    return 0;}


总结:同指针调用有相似之处吧

0 0
原创粉丝点击