This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

A link error related variadic-template


I used g++ 4.7.0 to compile the piece of code:

#include <stdio.h>
#include <boost/call_traits.hpp>

using namespace boost;

template <typename... Args> long add(Args...);

template <typename T> long add( typename call_traits<T>::param_type t) { return t; }

template <typename A, typename... Args>
long add( typename call_traits<A>::param_type a, typename call_traits<Args>::param_type... args )
{
        return a + add( args... );
}

int main()
{
        char c = 0;
        short s = 1;
        int i = 2;
        long l = 3;
        long n = add( c, s, i, l );

        return 0;
}

And I encountered a link error:
/tmp/cc8rJ4xe.o: In function `main':
variadic-templates.cpp:(.text+0x33): undefined reference to `long add<char, short, int, long>(char, short, int, long)'
collect2: error: ld returned 1 exit status

Is there anyone who can help me to resolve the problem? Thanks very much!

Sincerely,
Cyril

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]