小编bou*_*aet的帖子

从模板参数继承并在c ++中向上转发

我曾尝试在VS2008中使用此代码(并且可能在示例中包含了太多上下文...):

class Base
{
    public:
    void Prepare() {
       Init();
       CreateSelectStatement();
       // then open a recordset
    }
    void GetNext() { /* retrieve next record */ }
    private:
    virtual void Init() = 0;
    virtual string CreateSelectStatement() const = 0;
};
class A : public Base
{
   public:
   int foo() { return 1; }
   private:
   virtual void Init() { /* init logic */ }
   virtual string CreateSelectStatement() { /* return well formed query */ }
};

template<typename T> class SomeValueReader : protected T …
Run Code Online (Sandbox Code Playgroud)

c++ polymorphism templates casting crtp

2
推荐指数
1
解决办法
2057
查看次数

标签 统计

c++ ×1

casting ×1

crtp ×1

polymorphism ×1

templates ×1