Template class, function specialization

后端 未结 3 1296
旧巷少年郎
旧巷少年郎 2021-02-09 13:40

I want to have a template class that looks something like what I have down below. Then, I want a function in it with a template specialization depending on a CLASS template para

3条回答
  •  深忆病人
    2021-02-09 14:12

    This is called partial template specialisation. It looks like this:

    template
    class FooBase
    {
    };
    
    template 
    class Foo : public FooBase<_T,num>
    {
        void Func()
        {
            printf("Hello world!");
        }
    };
    
    
    template 
    class Foo<_T,1> : public FooBase<_T,num>
    {
        void Func()
        {
            printf("Hi!");
        }
    }
    

提交回复
热议问题