function template overloading

前端 未结 4 631
执念已碎
执念已碎 2020-12-04 14:39

Can anybody summarize the idea of function template overloading? What matters, template parameter or function parameter? What about the return value?

For example, g

4条回答
  •  生来不讨喜
    2020-12-04 15:15

    I stand corrected - see the comments below. I won't change any of my original post, as that would remove the context of the responses. I thank the commenters for their input, and for being so kind as to not vote me down


    Consider templating to be like the macro pre-processor, which expands #defines before the compiler gets to see them.

    The compiler will "expand" your template parameters and then look at your function declarations. So, template parameter == function parameter. If you declare the same function twice, you will get an error.

    You ask about return type. That is part of the function's 'signature'. Two functions with the same parameters but different return types are two different functions.

提交回复
热议问题