Multiple functions using the same template?

后端 未结 1 1848
旧巷少年郎
旧巷少年郎 2021-02-20 05:04

Is it possible to include more than one function in the same template instead of rewriting the template twice? Like if you were writing:

template 

        
1条回答
  •  不要未来只要你来
    2021-02-20 06:04

    Grouping them inside a class template would achieve that.

    template 
    struct Functions {
        static void A() { /*...*/ }
        static void B() { /*...*/ }
    };
    

    However, you lose the ability to deduce T from the functions' arguments, and the calling syntax is longer :

    Functions::A();
    

    0 讨论(0)
提交回复
热议问题