Template specialization and inheritance

后端 未结 3 957
北荒
北荒 2021-02-01 04:21

Suppose I have a template class with a lot of functions and I want to specialize them to change only a few of them and keep the other ones exactly as specified in the base templ

3条回答
  •  無奈伤痛
    2021-02-01 05:09

    Another solution would be to add a level of indirection in the function you want to redefine, i.e.

    template
    struct foo
    {
        template
        void bar_impl()
        {
            //generic function
        }
    
        void bar()
        {
            bar_impl();
        }
    };
    

    Then you can specialize each function individually for each type or specialize the whole type as wanted.

提交回复
热议问题