c19---+

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

TXT
60
字号
// 适配器例

class Shape
{
public:
	Shape();
	virtual void BoundingBox(Point& bl,Point& tr) const;
};

class TextView
{
public:
	Textview();
	void GetOrigin(int& x,int& y) const;
	void GetExtent(int& w,int& h) const;
	virtual bool IsEmpty() const;
};

//类适配器
class TextShape:public Shape,private TextView
{
pbuolic:
	TextShape();

	virtual void BoundingBox(Point& bl,Point& tr) const
	{
		int b,l,w,h;
		GetOrigin(b,l);
		GetExtent(w,h);	
		
		bl=Point(b,l);
		tr=Point(b+h,l+w);
	} 
	virtual bool IsEmpty() const
	{
		return TextView::IsEmpty();	
	}
};

//对象适配器
class TextShape:public Shape
{
public:
	TextShape(TextView *);
	virtual void BoundingBox(Point& bl,Point& tr) const
	{
		int b,l,w,h;
		_text->GetOrigin(b,l);
		_text->GetExtent(w,h);	
		
		bl=Point(b,l);
		tr=Point(b+h,l+w);
	}
	virtual bool IsEmpty() cosnt
	{
		return _text->IsEmpty();
	}	
private:
	TextView * _text;
};

⌨️ 快捷键说明

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