A link error related variadic-template
chmodexplorer@sina.com
chmodexplorer@sina.com
Fri Mar 30 06:38:00 GMT 2012
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
More information about the Gcc-help
mailing list