This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
A link error related variadic-template
- From: <chmodexplorer at sina dot com>
- To: "" <gcc-help at gcc dot gnu dot org>
- Date: Fri, 30 Mar 2012 16:48:23 +0800
- Subject: A link error related variadic-template
- Reply-to: chmodexplorer at sina dot com
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