fatal error LNK1120 in VC++

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

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;
}
//------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top