C
cna
The following code does not compile in VS 2010 Visual C++.
I get the error:
error LNK2019: unresolved external symbol "public: __thiscall
testTemplate<double>::testTemplate<double>(void)" (??0?
$testTemplate@N@@QAE@XZ) referenced in function _main main.obj
But if I move the code between
and
into the file main.cpp, the code compiles.
I am not sure why the compiler is complaining about the testTemplate
class but not about the test class.
I appreciate any help in this matter. Thanks
I get the error:
error LNK2019: unresolved external symbol "public: __thiscall
testTemplate<double>::testTemplate<double>(void)" (??0?
$testTemplate@N@@QAE@XZ) referenced in function _main main.obj
But if I move the code between
Code:
// Begin Comment
and
Code:
// End Comment
into the file main.cpp, the code compiles.
I am not sure why the compiler is complaining about the testTemplate
class but not about the test class.
I appreciate any help in this matter. Thanks
Code:
//File test.h
#include "stdafx.h"
template<typename T>
class testTemplate
{ protected: T templateKey_;
public : testTemplate();
};
class test
{
protected: int key_;
public: test();
};
//----------------------------------
//File test.cpp
#include <iostream>
#include "test.h"
test::test() { std::cout << "test object created." << std::endl;
key_ = -1; };
// Begin Comment
template<typename T>
testTemplate<T>::testTemplate() : templateKey_(-5) { std::cout <<
"testTemplate object created." << std::endl; };
// End Comment
//------------------------------------
// File main.cpp
#include "stdafx.h"
#include <iostream>
#include "test.h"
int _tmain(int argc, _TCHAR* argv[])
{
test tc = test();
testTemplate<double> tct = testTemplate<double>();
std::cin.get();
return 0;
}
//------------------------------------------------------