If you want to use a function from different cpp files you have to make the declaration (the function signature) available to both. In the case of a template function, the same goes for its definition! To avoid code duplication, the right place to put this is a header file, not a cpp file.
// file dump.hpp
template< size_t N >
void cdecl _DumpWin32StructFields( WCHAR (&szBuffer)[N], LPCWSTR pszFormat, ... )
{
va_list pFirstParam ;
va_start( pFirstParam, pszFormat ) ;
StringCchVPrintf( szBuffer, N,pszFormat, pFirstParam ) ;
va_end( pFirstParam ) ;
}
// file foo.cpp
#include "dump.hpp"
void foo() {
WCHAR buffer[20];
_DumpWin32StructFields(buffer, _T("Hello World!"));
}
// file bar.cpp
#include "dump.hpp"
void bar() {
WCHAR buffer[30];
_DunpWin32StructFields(buffer, _T("Goodbye Cruel World!"));
}
This will force the compiler to instantiate and create code for your template function for both foo.obj and bar.obj, and the linker won't have trouble finding them.