c++ pimpl idiom : Implementation depending on a template parameter

前端 未结 1 494
野趣味
野趣味 2021-01-16 20:27

In this question I unsuccessfully asked how to use different pimpl implementation depending on a template argument.

Maybe this example ilustrates better what I am tr

相关标签:
1条回答
  • 2021-01-16 21:11

    What you're trying to do is not allowed by the language.

    § 14.7.3.16 (FCD 2010-03-26) states:

    In an explicit specialization declaration for a member of a class template or a member template that appears in namespace scope, the member template and some of its enclosing class templates may remain unspecialized, except that the declaration shall not explicitly specialize a class member template if its enclosing class templates are not explicitly specialized as well. In such explicit specialization declaration, the keyword template followed by a template-parameter-list shall be provided instead of the template<> preceding the explicit specialization declaration of the member. The types of the template-parameters in the template-parameter-list shall be the same as those specified in the primary template definition.

    [ Example:
    template <class T1> class A {
        template<class T2> class B {
            template<class T3> void mf1(T3);
            void mf2();
        };
    };
    template <> template <class X>
    
    class A<int>::B {
        template <class T> void mf1(T);
    };
    template <> template <> template<class T>
    void A<int>::B<double>::mf1(T t) { }
    template <class Y> template <>
    void A<Y>::B<double>::mf2() { } // ill-formed; B<double> is specialized but
    // its enclosing class template A is not
    —end example ]
    
    0 讨论(0)
提交回复
热议问题