类的定义以及类成员函数的互相调用

#include <iostream>
#include <string>
#include<algorithm>
using namespace std;

class POINT
{
private:
    int x;int y;
public:
    void set(int a,int b)
    {x=a,y=b;}

    void get()
    {
        cout<<"x="<<x<<"y="<<y<<endl;
    }

    void change(int a,int b)
    {
        POINT A;
        A.set(a,b);//类的成员函数的相互调用。
        *this=A; //this 指针的的应用。
    }

};//类的定义,后边的分号不能少。





int main()
{

    POINT B;
    int i=40,j=80;
    B.set(i,j);
    B.get();

    B.change(20,30);
    B.get();







    return 0;
}

猜你喜欢

转载自blog.csdn.net/gaocui883/article/details/88345036