S
Shailesh Humbad
I am trying to define some template classes for the first time. But I
am getting the following error when I try to use the template class:
TestTemplatesConsoleApp error LNK2019: unresolved external symbol
"public: __thiscall my<int>::my<int>(void)" (??0?$my@H@@QAE@XZ)
referenced in function _main
When I move the class definition from my.cpp to test.cpp, the error
goes away. What am I doing wrong? Code is below:
--------------
Test.cpp
--------------
#include "my.h"
int _tmain(int argc, _TCHAR* argv[])
{
class my<int> pMy;
// The line below works fine.
// class my2 pMy2;
}
----------
my.h
----------
template<class DE>
class my {
public:
my();
DE testfunc();
private:
int myint;
};
class my2 {
public:
int myint;
my2();
};
---------------
my.cpp
---------------
#include "my.h"
template<class DE>
my<DE>::my()
{
this->myint = 0;
}
my2::my2() {
this->myint = 0;
}
am getting the following error when I try to use the template class:
TestTemplatesConsoleApp error LNK2019: unresolved external symbol
"public: __thiscall my<int>::my<int>(void)" (??0?$my@H@@QAE@XZ)
referenced in function _main
When I move the class definition from my.cpp to test.cpp, the error
goes away. What am I doing wrong? Code is below:
--------------
Test.cpp
--------------
#include "my.h"
int _tmain(int argc, _TCHAR* argv[])
{
class my<int> pMy;
// The line below works fine.
// class my2 pMy2;
}
----------
my.h
----------
template<class DE>
class my {
public:
my();
DE testfunc();
private:
int myint;
};
class my2 {
public:
int myint;
my2();
};
---------------
my.cpp
---------------
#include "my.h"
template<class DE>
my<DE>::my()
{
this->myint = 0;
}
my2::my2() {
this->myint = 0;
}