Passing the template Variadic argument package to the following function

In my debug code, I've done my own rework of printf () (classic).

    template<typename T, typename ...Args>
    void Printf(wchar_t const * message, T value, Args ...args);
    void Printf(wchar_t const * message);
    void Printf();

      

It uses variation patterns and works great.

Now I want to use Printf () in several functions that will take almost the same arguments, but execute Printf () in different ways. Here is one of the Printf () client functions

template<typename ...Args>
void Debug::Line(unsigned int in_tabs, wchar_t const * in_string, Args...in_args){
    for (unsigned int i = 0; i < in_tabs; ++i)
        Tab();
    Printf(in_string, in_args...);
    NewLine();
}

      

As soon as I start using this construct, I start getting UNRESOLVED linker errors

error LNK2019: unresolved external symbol "public: static void __cdecl Nerv::Debug::Line<>(unsigned int,wchar_t *)" (??$Line@$$$V@Debug@Nerv@@SAXIPA_W@Z) referenced in function "public: void __thiscall Nerv::UI::NervUIRect::DebugRect(void)" (?DebugRect@NervUIRect@UI@Nerv@@QAEXXZ)
error LNK2019: unresolved external symbol "public: static void __cdecl Nerv::Debug::Line<int,int>(unsigned int,wchar_t *,int,int)" (??$Line@HH@Debug@Nerv@@SAXIPA_WHH@Z) referenced in function "public: void __thiscall Nerv::UI::NervUIRect::DebugRect(void)" (?DebugRect@NervUIRect@UI@Nerv@@QAEXXZ)

      

This is strange to me, because I first tested this construction on a simpler case and it worked great.

template<typename T,typename...Ts>
void Printf(T value,Ts...args){
    OutputDebugString(value);
    Printf(args...);
}
void Printf(){

}

template<typename...Args>
void UsePrintf(Args...args){
    Printf(args...);
}

      

The difference from the simple case is that all these functions (which don't work) are static members of the Debug class and that there are some additional function arguments. So how am I supposed to do this?

+3


source to share


1 answer


As TartanLlama pointed out, the body of the template function had to be available / visible in the header file either by adding the definition and togather declaration to the header, or by including a cpp file with the function implementation at the end of the header



0


source







All Articles