c++ template function overlading argument deduction with const argument -
i having following setup:
template <typename t> void foo(t& t); void foo(const int& t); void f() { int i; foo(i); //unresolved reference "void foo<int>(int &)" foo(const_cast<const int&>(i)); //unresolved reference "void foo(int const &)" }
in first call foo, compiler tries call template version, since argument of non-template 1 not match type of i. in second call non-template version called. using microsoft c++ compiler version 10. standard behavior? if type not matched, if has const modifier, template function called?
edit: know 2 functions don't have definition, pointing out linker complains about, make more clear compiler wants call.
is standard behavior? if type not matched, if has const modifier, template function called?
yes, well-defined standard.
if there no exact match, template used, because instantiated template version better match 1 requires conversion (even int &
int const&
conversion).
Comments
Post a Comment