Note that there are some explanatory texts on larger screens.

plurals
  1. POInheriting Template class or composition errors
    text
    copied!<p>Hi am a newbie and having problems with class templates. I have tried to use composition and inheritance of a template class but with both ending up in errors. Mainly, errors of this type for several times:</p> <p>error LNK2019: unresolved external symbol.........referenced in function "public: __thiscall.</p> <p>I will show the example for composition. Note that these errors refers to the functions that I have used in the derived class that were from the base class. In this case, function1 and function2 were used and will result in the error above.</p> <p><strong>Base Class</strong></p> <pre><code>#ifndef ClassA_H #define ClassA_H #include &lt;string&gt; using namespace std; template &lt;class T&gt; ClassA { public: void function1 (double z, T i); T function2 (T var); private: double number; T *array T *array2 }; #endif </code></pre> <p><strong>Body</strong></p> <pre><code>template &lt;class T&gt; void ClassA&lt;T&gt;::function1 (double z, T i) {} template &lt;class T&gt; T classA&lt;T&gt;::function2 (T var) {} </code></pre> <p><strong>Composition</strong></p> <pre><code>#ifndef ClassB_H #define ClassB_H #include "ClassA.h" ClassB { public: ClassB(); private: ClassA &lt;int&gt; class; }; #endif </code></pre> <p><strong>Body of class B (.cpp)</strong></p> <pre><code>ClassB::ClassB(){ class.function1(24.3,15); class.function2 (14); } </code></pre> <p>I have done much research where it is solved by using this-> and classb &lt; int > ::function1 and others for template class. But it is not working for my case of inheriting a template class. I then moved on to composition. My linker>System is also set to console. I'm using VS 2012.</p> <p>Thanks for your time guys.</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