C++ template function default value

后端 未结 5 1962
挽巷
挽巷 2020-12-03 12:09

Is it possible to define the default value for variables of a template function in C++?

Something like below:

template T sum(T a, T b,         


        
5条回答
  •  猫巷女王i
    2020-12-03 12:48

    Yes!

    However you should at least have an idea about what T could be or it's useless.

    You can't set the default value of template parameters for functions, i.e. this is forbidden:

    template void f(T a, T b);
    

提交回复
热议问题