5-3-1.cpp

来自「学习c++的ppt」· C++ 代码 · 共 41 行

CPP
41
字号
#include <iostream.h>
class  X  {
    private:
        int x;
        static int y;
    public:
        void Set(int i){ 
		    x=i;
		}
        void Display(){
		    cout<<"x="<<x<<",y="<<y<<endl;
		}
        friend class Y;
};

class Y  {
    private:
        X a;
    public:
        Y(int i, int j);
        void  Display();
};
int X::y = 10;
Y::Y(int i, int j)
{  
	a.x = i; 
	X::y=j; 
}
void Y::Display()
{ 
	cout<<"x="<<a.x<<", y="<<X::y<<endl;
}
void main()
{   X b;   
    b.Set(15);  
	b.Display();
    Y c(16, 19);  
	c.Display();   
	b.Display();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?