proj8_05.cpp

来自「C++程序设计教程的全部源代码 包含与教程同步的PPT 方便学习」· C++ 代码 · 共 40 行

CPP
40
字号
#include "iostream.h"
class X
{
public:
	friend class Y;
	void Set(int i)
	{
		x = i;
	}
	void display()
	{
		cout << "x = " << x << ",y = " << y << endl;
	}
private:
	int x;
	static int y;
};
int X::y = 10;
class Y
{
public:
	Y(int i , int j)
	{
		a.x = i;
		X::y = j;
	}
	void display_X()
	{
		cout << "x = " << a.x << ".y = " << X::y << endl;
	}
private:
	X a;
};

void main()
{
	Y c(33 , 44);
	c.display_X();
}

⌨️ 快捷键说明

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