Partially specializing member-function implementations

前端 未结 4 691
温柔的废话
温柔的废话 2021-01-20 04:58

I\'m currently refactoring some code the explicitly specializes a member function of a class template with two template parameters.

template 

        
4条回答
  •  被撕碎了的回忆
    2021-01-20 05:12

    You can make Base class , where you can define all your members except bar() and then create derivative classes(one for general purpose, one for SomeType):

    template 
    class FooBase
    {
           // All other members 
    };
    
    template 
    class Foo:public FooBase
    {
    public:
          void bar()
          {
    
          }
    };
    
    struct SomeType {};
    
    template 
    class Foo:public FooBase
    {
    public:
        void bar()
        {
    
        }
    };
    
    int main()
    {
        Foo b;
        b.bar();
    }
    

提交回复
热议问题