P
PGK
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.
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;}
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.
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;}