template function call

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mar11
    New Member
    • Sep 2009
    • 38

    template function call

    H all,

    I have seen an example in which the template function is called as the following:

    object_test.tem plate foo<argument>(f unxtion_argumen t);

    Could someone clarify me why template is added by function call at this way?

    Best regards
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    A template requires the compiler to substitute the correct type for the generic one coded in the template.

    If the compiler cannot deduce the correct type from the function argument, then you can explicitly state the type the compiler should use:

    Code:
    MyFunction<int>();
    In this case the template function has no arguments so there is no way for the compiler to figure out that an int should be used to specialize the template.

    Comment

    Working...