Note that there are some explanatory texts on larger screens.

plurals
  1. POTemplate Compilation
    primarykey
    data
    text
    <p>Can someone pelase explain to me how I can avoid the error below?</p> <p>I think I am following all I have read on template compilation but still get an error. Sorry for asking this - it seems trivial but I am stuck!</p> <p>Thanks, Paolo</p> <pre><code>1&gt;------ Build started: Project: BitsAndPieces, Configuration: Release Win32 ------ 1&gt; NonTemplateFunctionFriend_main.cpp 1&gt;NonTemplateFunctionFriend_main.obj : error LNK2001: unresolved external symbol "public: int __thiscall Paolo&lt;int&gt;::getMyOnlyMember(void)" (?getMyOnlyMember@?$Paolo@H@@QAEHXZ) 1&gt;\\na-13\agnolucp\my documents\visual studio 2010\Projects\BitsAndPieces\Release\BitsAndPieces.exe : fatal error LNK1120: 1 unresolved externals ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== </code></pre> <p><strong>main</strong></p> <pre><code>#include "NonTemplateFunctionFriend.h" #include&lt;iostream&gt; using namespace std; int main() { Paolo&lt;int&gt; Me; cout &lt;&lt; Me.getMyOnlyMember() &lt;&lt; endl; return 1; } </code></pre> <p><strong>NonTemplateFunctionFriend.h</strong></p> <pre><code>#ifndef NonTemplateFunctionFriend_H #define NonTemplateFunctionFriend_H #include &lt;iostream&gt; template&lt;class T&gt; class Paolo { private: T myOnlyMember; public: Paolo(): myOnlyMember(1000) {}; T getMyOnlyMember(); }; #include "NonTemplateFunctionFriend.cpp" #endif </code></pre> <p><strong>NonTemplateFunctionFriend.cpp</strong></p> <pre><code>#ifndef NonTemplateFunctionFriend_CPP #define NonTemplateFunctionFriend_CPP #include "NonTemplateFunctionFriend.h" template&lt;class T&gt; T getMyOnlyMember() { return myOnlyMember; } #endif </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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