Passing variadic template argument pack to next function

1.1k views Asked by At

I have done my own reimplementation of printf() (classic) in my debugging code.

    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 variadic templates and works perfectly fine.

Now I want to use Printf() in couple of functions that are going to accept almost same arguments but perform Printf() in different ways. Here is one of the client functions for Printf()

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 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)

It's strange to me, cause I've tested this construct on a simpler case first and it worked fine.

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 theese functions (that don't work) are static members of a Debug class and that there are some additional function arguments. So how am I supposed to deal with this?

1

There are 1 answers

0
Antiusninja On

As TartanLlama pointed the template function body needed to be available/seen in the header file either by putting the definition and declaration togather in the header or by including the cpp file with function implementation in the end of the header