The following code gives the link error:
[Linker Error] Unresolved external 'C1<int>::f()' referenced from D:\PROGRAM
FILES\BORLAND\C BUILDER5\PROJEC TS\MAIN.OBJ
Using Borland CBuilder5. If i define the body of the function f in the
header file1.h, it links ok. I believe this is normal language behaviour
because all the ATL libs are defined in the headers. But is there another
way to do it so i can define my functions in the cpp file?
file1.h:
/////////////////////////////////
template<class T>
class C1
{
public:
static void f();
};
/////////////////////////////////
file1.cpp:
/////////////////////////////////
template<class T>
void C1<T>::f()
{
}
/////////////////////////////////
main.cpp:
/////////////////////////////////
#include "file1.h"
int main(int argc, char* argv[])
{
C1::f();
return 0;
}
[Linker Error] Unresolved external 'C1<int>::f()' referenced from D:\PROGRAM
FILES\BORLAND\C BUILDER5\PROJEC TS\MAIN.OBJ
Using Borland CBuilder5. If i define the body of the function f in the
header file1.h, it links ok. I believe this is normal language behaviour
because all the ATL libs are defined in the headers. But is there another
way to do it so i can define my functions in the cpp file?
file1.h:
/////////////////////////////////
template<class T>
class C1
{
public:
static void f();
};
/////////////////////////////////
file1.cpp:
/////////////////////////////////
template<class T>
void C1<T>::f()
{
}
/////////////////////////////////
main.cpp:
/////////////////////////////////
#include "file1.h"
int main(int argc, char* argv[])
{
C1::f();
return 0;
}
Comment