S
Shivanand
Hello everyone,
Im facing problems with linking C++ templates in GCC on a MAC.
Following is the error GCC throws when I put template declaration in
".h" file and definition in ".cpp" file.
/usr/bin/ld: Undefined symbols:
JQualifier<double, 3>::JQualifier(int, long)
JQualifier<double, 3>::~JQualifier()
I get no errors when I put the class definitions inline (i.e. define
the instance methods inside the class). Can anyone please tell me what
I am doing wrong ?
Thanks in Advance
Following is the code snippet :
//--------------- JQualifier.h ---------------------------
template <typename T, int n>
class JQualifier
{
public :
JQualifier (int type, long uid);
~JQualifier () ;
};
//--------------- JQualifier.h ---------------------------
//--------------- JQualifier.cpp ---------------------------
#include "JQualifier.h"
template <typename T, int n>
JQualifier<T, n>::JQualifier (int type, long uid)
{
}
template <typename T, int n>
JQualifier<T, n>::~JQualifier ()
{
}
//--------------- JQualifier.cpp ---------------------------
//---------------- Main.cpp ----------------------------------
#include <iostream>
#include <JQualifier.h>
int main (int argc, char * const argv[]) {
JQualifier<double, 3> obj (1, 1) ;
return 0;
}
//---------------- Main.cpp ----------------------------------
Regards
Shivanand
Im facing problems with linking C++ templates in GCC on a MAC.
Following is the error GCC throws when I put template declaration in
".h" file and definition in ".cpp" file.
/usr/bin/ld: Undefined symbols:
JQualifier<double, 3>::JQualifier(int, long)
JQualifier<double, 3>::~JQualifier()
I get no errors when I put the class definitions inline (i.e. define
the instance methods inside the class). Can anyone please tell me what
I am doing wrong ?
Thanks in Advance
Following is the code snippet :
//--------------- JQualifier.h ---------------------------
template <typename T, int n>
class JQualifier
{
public :
JQualifier (int type, long uid);
~JQualifier () ;
};
//--------------- JQualifier.h ---------------------------
//--------------- JQualifier.cpp ---------------------------
#include "JQualifier.h"
template <typename T, int n>
JQualifier<T, n>::JQualifier (int type, long uid)
{
}
template <typename T, int n>
JQualifier<T, n>::~JQualifier ()
{
}
//--------------- JQualifier.cpp ---------------------------
//---------------- Main.cpp ----------------------------------
#include <iostream>
#include <JQualifier.h>
int main (int argc, char * const argv[]) {
JQualifier<double, 3> obj (1, 1) ;
return 0;
}
//---------------- Main.cpp ----------------------------------
Regards
Shivanand