Note that there are some explanatory texts on larger screens.

plurals
  1. POtemplate specialization multiply defined symbols
    primarykey
    data
    text
    <p>I know i'm missing something easy here but I've got a templated member function of a class which I've specialised.</p> <pre><code>MyClass { template&lt;typename T&gt; T GetTFromVariable(shared_ptr&lt;TOtSimpleVariable&gt; v, string s); } template&lt;typename T&gt; T MyClass::GetTFromVariable(shared_ptr&lt;TOtSimpleVariable&gt; v, string s) { throw std::runtime_error("Don't know how to convert " + ToString(v-&gt;GetString())); } template&lt;&gt; int MyClass::GetTFromVariable&lt;int&gt;(shared_ptr&lt;TOtSimpleVariable&gt; v, string s) { return v-&gt;GetInteger(); } template&lt;&gt; string MyClass::GetTFromVariable&lt;string&gt;(shared_ptr&lt;TOtSimpleVariable&gt; v, string s) { return v-&gt;GetString(); } // etc for other specialisations. </code></pre> <p>This is defined in my header file (as templates should be) but when I go and compile I get a bunch of mutliply defined symbols, a representative such error is: </p> <pre><code> OtCustomZenith_logic.lib(PtPathOutput.obj) : error LNK2005: "public: class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; __thiscall MyClass::GetTFromVariable&lt;class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; &gt;(class boost::shared_ptr&lt;class TOtSimpleVariable&gt;,class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt;)" (??$GetTFromVariable@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@CommandProperties@@QAE?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$shared_ptr@VTOtSimpleVariable@@@boost@@V12@@Z) already defined in TableFareSystem_test.obj </code></pre> <p>I can fix it by inlining the methods but I don't think that should be necessary... what did I forget?</p> <p>EDIT: I'm using Visual Studio 2010</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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