fatal error LNK1120 in VC++

11 views
Skip to first unread message

cna

unread,
Sep 23, 2011, 7:52:43 PM9/23/11
to
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[/code]

and

[code]// End Comment[/code]

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;
}
//------------------------------------------------------
[/code]
Reply all
Reply to author
Forward
0 new messages