我试图将Mixin模式与我的问题相匹配,我有一个多态性问题,我不知道如何有效地解决.在尝试重新设计程序之前,我想问你一些建议(也许有一些我不知道的很酷的c ++功能).
我想以非常直接和简单的方式呈现它,因此这里的用例可能没有意义.
我只是一Window堂课
struct WindowCreateInfo {
std::string title;
int x, y;
int width, height;
};
class Window {
public:
Window(const WindowCreateInfo &createInfo) :
title(createInfo.title),
x(createInfo.x),
y(createInfo.y),
width(createInfo.width),
height(createInfo.height) {}
const std::string &getTitle() const { return title; }
int getX() const { return x; }
int getY() const { return y; }
int getWidth() const { return width; }
int getHeight() const { return height; }
public:
protected:
std::string title;
int x, y;
int width, height;
};
Run Code Online (Sandbox Code Playgroud)
然后我定义了两个mixins …