Using declaration for type-dependent template name

后端 未结 1 1115
清酒与你
清酒与你 2021-02-19 08:21

When CRTP is used inside a template, (or generally when a template parameter is passed as a base class template argument), is it impossible to name the base\'s member templates

相关标签:
1条回答
  • 2021-02-19 08:51

    The following works fine with C++11:

    #include <iostream>
    
    template< typename d >
    struct base {
        template< typename >
        struct ct {};
    
        template< typename >
        void ft() {std::cerr << "cheesecake" << std::endl;}
    };
    
    template< typename x >
    struct derived : base< derived< x > > {
      template<typename X>
        using ct = typename derived::base::template ct<X>; // new in C++11
      using derived::base::ft;
    };
    
    int main()
    {
      derived<int>::ct<float> c;
      derived<int> a;
      a.ft<int>();
    }
    

    If that is not what you wanted, can you please give an example of how you would want to use ct and ft?

    0 讨论(0)
提交回复
热议问题