⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄

📁 C语言相关程序
💻
字号:
#include<iostream.h>
class A;
class B
{
public:
	int & geti();
	B();
	B(B&);
	~B();
	B& operator=(B&);
private:
	A *pA;
	friend class A;
};
class A
{
public:
	void addout(B &b)
	{
		cout<<"the address of A in B is: "<<b.pA<<endl;
	}
private:
	int i;
	friend int &B::geti();
};
void main()
{
	B b;
	A a;
	b.geti()=1;
	a.addout(b);
	cout<<"b.pA->i"<<b.geti()<<endl;
}
B::B()
{
	pA=new A;
}
B::B(B& b)
{
	pA=new A(*(b.pA));
}
B::~B()
{
	delete pA;
}

B& B::operator=(B& b)
{
	pA=new A(*(b.pA));
	return *this;
}
int & B::geti()
{
	return pA->i;
}

⌨️ 快捷键说明

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