Note that there are some explanatory texts on larger screens.

plurals
  1. PODefine sorting method ( that use std::sort for sorting) of a templated class in dll and calling it from another project
    text
    copied!<p>Sorry for my bad English. I have 2 projects. Project 1 is a MFC dll that contains class CMyContainer, class CEmployee. Project 2 is my main project. In project 2, I created an instance of CMyContainer of type CEmployee. Now I want to sort the container but I got an error </p> <p>"<code>error LNK2019: unresolved external symbol "bool __cdecl MyComparer(class CEmployee *,class CEmployee *)" (?MyComparer@@YA_NPAVCEmployee@@0@Z) referenced in function "public: void __thiscall CMyContainer&lt;class CEmployee&gt;::sortContainer(void)" (?sortContainer@?$CMyContainer@VCEmployee@@@@QAEXXZ)</code>"</p> <p>How can I fix this problem?</p> <p>// file MyContainer.h in project 1</p> <pre><code>#include &lt;vector&gt; template &lt;class T&gt; class _declspec(dllexport) CMyContainer { public: CMyContainer(void); ~CMyContainer(void); ... void sortContainer(); private: std::vector&lt;T*&gt; items; typename std::vector&lt;T*&gt;::iterator it; }; template &lt;class T&gt; void CMyContainer&lt;T&gt;::sortContainer() { typedef bool (*comparer_t)(T*,T*); comparer_t cmp = &amp;MyComparer; std::sort(items.begin(), items.end(), cmp); } //File Employee.h in project 1 #include "MyContainer.h" class _declspec(dllexport) CEmployee { public: CEmployee(void); ~CEmployee(void); void setEmployeeCode(CString); CString getEmployeeCode(); friend bool MyComparer(CEmployee*, CEmployee*); private: CString m_szEmployeeCode; } //File Employee.cpp in project 1 void CEmployee::setEmployeeCode(CString val){ m_szEmployeeCode= val; } CString CEmployee::getEmployeeCode(){ return m_szEmployeeCode; } bool MyComparer(CEmployee*pEmp1, CEmployee*pEmp2) { return (pEmp1-&gt;getEmployeeCode().Compare(pEmp2-&gt;getEmployeeCode())&lt;0); } //File main.cpp in project 2 #include &lt;..\Models\MyContainer.h&gt; #include &lt;..\Models\Employee.h&gt; ... CMyContainer&lt;CEmployee&gt; *pListEmployee; ... // insert into pListEmployee // sort pListEmployee pListEmployee.sortContainer();//-&gt; This command cause error </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload