No type named 'type' in CTRP derived class

后端 未结 4 564
猫巷女王i
猫巷女王i 2020-12-31 11:22

I\'ve been experimenting with the Curiously Recurring Template Pattern for a generic single-argument functor and have two implementations: one using a template template para

4条回答
  •  攒了一身酷
    2020-12-31 12:08

    Your code could be simplified to

    template class
    Base
    {
        using Ftype = typename TDerived::type;
    };
    
    template class
    Derived: public Base>
    {
        using type = T;
    };
    
    Derived wat;
    

    It does not work because at the point of Base instantiation Derived class is not complete, and compiler is not aware of Derived::type existence yet.

提交回复
热议问题