delegation.cpp
来自「设计模式 几个常见的设计模式源代码 Delegation Factory等」· C++ 代码 · 共 50 行
CPP
50 行
#include <iostream>
using namespace std;
class Rectangle
{
public:
Rectangle( int height, int width ) : _height( height ), _width( width )
{
}
public:
int Area()
{
return _height*_width;
}
private:
int _height;
int _width;
};
class Target
{
virtual int Area() = 0;
};
class Window : public Target
{
public:
Window( Rectangle& rect ) : _rect( rect )
{
}
public:
int Area()
{
return _rect.Area();
}
private:
Rectangle& _rect;
};
int main()
{
Rectangle rect( 10, 20 );
Window win( rect );
win.area();
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?