Note that there are some explanatory texts on larger screens.

plurals
  1. POVisualStudio C++ Linker problem with template classes
    text
    copied!<p>I still can't get it to work..</p> <p>After I had to separate implementation from definition of one of my generic classes because of a forward declaration, i now get Linker errors when trying to build.</p> <p>IShader.h:</p> <pre><code>template &lt;typename ShadeType&gt; class IShader { public: template &lt;typename T&gt; bool getProperty(const std::string&amp; propertyName, ShaderProperty&lt;T&gt;** outProp); }; </code></pre> <p>so it's a generic class with a generic member function with a different generic type</p> <p>implementation looks like this:</p> <pre><code>#include "MRIShader.h" template &lt;typename ShadeType&gt; template &lt;typename T&gt; bool IShader&lt;ShadeType&gt;::getProperty(const std::string&amp; propertyName, ShaderProperty&lt;T&gt;** outProp){ std::map&lt;std::string, IShaderProperty* &gt;::iterator i = m_shaderProperties.find(propertyName); *outProp = NULL; if( i != m_shaderProperties.end() ) { *outProp = dynamic_cast&lt;ShaderProperty&lt;T&gt;*&gt;( i-&gt;second ); return true; } return false; } </code></pre> <p>but i get Linker errors like this one:</p> <pre><code>error LNK2001: Nicht aufgelöstes externes Symbol ""public: bool __thiscall IShader&lt;class A_Type&gt;::getProperty&lt;bool&gt;(class std::basic_string&lt;char,struct std::char_traits&lt;char&gt;,class std::allocator&lt;char&gt; &gt; const &amp;,class ShaderProperty&lt;bool&gt; * *)" (??$getProperty@_N@?$IShader@VA_Type@@@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAPAV?$ShaderProperty@_N@@@Z)". SceneParser.obj </code></pre> <p>for bool, but also for many other types. I already read through this article: <a href="http://www.parashift.com/c++-faq-lite/templates.html" rel="nofollow noreferrer">http://www.parashift.com/c++-faq-lite/templates.html</a></p> <p>but adding </p> <pre><code>templace class IShader&lt;bool&gt;; </code></pre> <p>in the end of IShader.cpp doesn't solve the problem. I also tried to add the 'export' keyword before the keyword 'template' in the implementation, but this just gives me a syntax error.</p> <p>What's the proper way to declare and implement my template class, which has templated member methods (with a different template type!) in separate files (.h and .cpp) without getting Linker errors?</p> <p>thanks!</p>
 

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