Multiple functions using the same template?

后端 未结 1 1843
旧巷少年郎
旧巷少年郎 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条回答
  • Grouping them inside a class template would achieve that.

    template <class T>
    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<double>::A();
    
    0 讨论(0)
提交回复
热议问题