宽窄接口分离的代码

来源:互联网 发布:c语言谭浩强课后答案 编辑:程序博客网 时间:2024/04/27 17:09
template<typename wide, typename narraw>
class wrap : public narraw
{
public:
    virtual wide& toWide() = 0;
    virtual const wide& toWide() const  = 0;
protected:
    ~warp(){}
};

template<typename wide, typename narraw>
class rich : public wide, wrap<wide, narraw>
{
    virtual wide& toWide() { return *this; }
    virtual const wide& toWide() const  { return *this; }
    narraw& toNarraw() { return *this; }
    const narraw& toNarraw() const  { return *this; }
};