Export (0) Print
Expand All
Expand Minimize

Compiler Warning (level 4) C4347

behavior change: 'function template' is called instead of 'function'

In Visual Studio .NET, if you had a template function and a nontemplate function with the same name as the template function, the compiler incorrectly treated the nontemplate function as a specialization of the template function.

For code that works the same in all versions of Visual C++, add template<> above the nontemplate function, making it a real explicit specialization.

For more information, see Summary of Compile-Time Breaking Changes.

This warning is off by default. For more information, see Compiler Warnings That Are Off by Default.

The following sample generates C4347.

// C4347.cpp
// compile with: /W4 /EHsc
#pragma warning (default : 4347)

template <typename T>
void f(T t) { T i = t; i = 0; }

void f(int i) { i++; }

// OK
template <typename T>
void f2(T t) { T i = t; i = 0; }

template <>
void f2(int i) { i++; }

int main() {
   f(5);   // regular function call
   f<int>(5);   // C4347 calls implicit instantiation

   f2(5);
   f2<int>(5);
}

Community Additions

ADD
Show:
© 2014 Microsoft