Tuesday 14 November 2017

c++ - error LNK2019: unresolved external symbol "public: __thiscall

itemprop="text">


I have a class like



template             T>
class LinkedListItem
{
public:

LinkedListItem(T value);
LinkedListItem(const LinkedListItem&
rhs);
T getValue(void);

LinkedListItem&
getNext(void);
void setNext(LinkedListItem& next);

LinkedListItem& operator=(const LinkedListItem&
rhs);
~LinkedListItem();
private:
T _value;

LinkedListItem& _next;

};



I am
trying to write a unit test
like



TEST_CLASS(LinkedListUnitTests)
{
public:


TEST_METHOD(Add_to_An_Empty_Linked_List)
{

LinkedListItem item(1);

}

//private:

};


When
I try to just build the above code I get the ugly error
-



error LNK2019: unresolved external symbol
"public: __thiscall cpp::libraries::datastructures::LinkedListItem::LinkedListItem(int)"
(??0?$LinkedListItem@H@datastructures@libraries@cpp@@QAE@H@Z) referenced in function
"public: void __thiscall
CppLibrariesTests::LinkedListUnitTests::Add_to_An_Empty_Linked_List(void)"
(?Add_to_An_Empty_Linked_List@LinkedListUnitTests@CppLibrariesTests@@QAEXXZ)



I
am using Visual Studio
2012.




Interestingly, If I add
template in the unit test class like below the compile error goes away but the tests are
not discovered and I can't run
them.



template            T>
TEST_CLASS(LinkedListUnitTests){..}


I
am trying to pick up C++ after a long time so I won't be surprised if I am doing
something very stupid. Any thoughts anyone?


class="post-text" itemprop="text">
class="normal">Answer



Templates
must ideally be implemented inline. Second pass of compiler cannot re use the CPP file
that has the implementation. Or, you need to #include the
CPP
file also.




href="http://www.codeproject.com/Articles/257589/An-Idiots-Guide-to-Cplusplus-Templates-Part"
rel="nofollow">Refer this article



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...