C++: error “explicit specialization in non-namespace scope”

前端 未结 2 2194
情深已故
情深已故 2021-02-20 11:12
template
class Bimap {
public:
    class Data {
    private:
        template Data& set(T);
        template<>         


        
2条回答
  •  日久生厌
    2021-02-20 11:23

    One way forget templates, overload:

    Data& set(T1 v) { /*...*/ }
    

    but here is a trick which I use sometimes

    you can specialize class template within class:

    class {
        template
        struct function_ {
            static void apply(T);
        };
    
        template<>
        struct function_ {
            ...
        };
    
        template
        void function(T t) { return function_::apply(t); }
    

提交回复
热议问题