c20-

来自「C++面向对象课程设计课件」· 代码 · 共 40 行

TXT
40
字号
//中介者

class Couple
{
public:
	Couple(Husband * h,Wife	* w);

	char * GetOtherName(Person * person)
		{ if (person==husband)
			return wife->GetName();
		   else
			return husband->GetName();	
		}
private:
	Husband * husband;
	Wife	* wife;
};

class Person
{
public:
	char * GetName() const;
private:
	char * name;
	Couple * couple;
};

class Husband:public Person
{
public:
	virtual char * GetWifeName() cosnt
		{ return couple->GetOtherName(this);}
};
class Wife:public Person
{
public:
	char * GetHusbandName() const
		{ return couple->GetHusbandName();}
};

⌨️ 快捷键说明

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