Template argument deduction of return type

  c++, template-argument-deduction, templates

How is the return type here being deduced? IOW, how based on the return type of the function pointer does it instantiate the correct function.

template<typename From, typename To>
To Convert(const From& f) 
{
    std::cout << sizeof(From) << " " << sizeof(To) << std::endl;    
    return To(f);
}



int main()
{
    float (*p)(const double &e) = Convert;
    p(20.2);

}

This prints

8 4

Source: Windows Questions C++

LEAVE A COMMENT