bilbobaggio
Technical User
I am getting a linker error whe nusing templates. If i remove the templates from the following sample and make the num member of A an int by default i get no error.
I have header file (A.h):
template <class T>
class A {
public: A(): num(1) {}
~A() {}
void print();
private: T num;
};
..... and implemention file (A.cpp)
#include "A.h"
#include <iostream.h>
template <class T>
void A<T>:rint()
{ cout << num << endl; }
When i compile a simple program
A<int> a;
a.print()
i get the following error:
error LNK2001: unresolved external symbol "public: void __thiscall A<int>:rint(void)" (?print@?$A@H@@QAEXXZ)
I have header file (A.h):
template <class T>
class A {
public: A(): num(1) {}
~A() {}
void print();
private: T num;
};
..... and implemention file (A.cpp)
#include "A.h"
#include <iostream.h>
template <class T>
void A<T>:rint()
{ cout << num << endl; }
When i compile a simple program
A<int> a;
a.print()
i get the following error:
error LNK2001: unresolved external symbol "public: void __thiscall A<int>:rint(void)" (?print@?$A@H@@QAEXXZ)