Specializing function template for reference types

后端 未结 3 1770
南旧
南旧 2020-12-19 00:46

Why is the output of this code :

#include   
template void f(T param) 
{ 
   std::cout << \"General\" << std::e         


        
3条回答
  •  既然无缘
    2020-12-19 01:10

    A reference is just an alias, not a type. So when you call f(z), it matches the first version with T=int, which is a better option that T=int&. If you change T to T&, then both int and int& arguments will call the second version.

提交回复
热议问题