Note that there are some explanatory texts on larger screens.

plurals
  1. POcannot declare variable to be of type because the following virtual functions are abstract
    text
    copied!<p>I have the following code </p> <p>Classes.h</p> <pre><code>#ifndef CLASSES_H #define CLASSES_H #include &lt;iostream&gt; using namespace std; template&lt; class T1, class T2&gt; class class1 { public: virtual void method1(int) const =0; virtual void method2(class1&amp;) const =0; }; template&lt; class T1&gt; class class2:public class1&lt;T1,int&gt; { public: void method1(int) const; void method2(class2&amp;) const; }; template&lt; class T1&gt; void class2&lt;T1&gt;::method1(int i) const { cout&lt;&lt;"class2::method1 - before Call %i"&lt;&lt;endl; cout&lt;&lt;"class2::method1 - after Call"&lt;&lt;endl; } template&lt; class T1&gt; void class2&lt;T1&gt;::method2(class2&amp; c2) const { cout&lt;&lt;"class2::method2 - before Call"&lt;&lt;endl; cout&lt;&lt;"class2::method2 - after Call"&lt;&lt;endl; } #endif </code></pre> <p>main.cpp</p> <pre><code>#include &lt;cstdlib&gt; #include &lt;iostream&gt; using namespace std; #include "Classes.h" int main(int argc, char *argv[]) { class2&lt;int&gt; c2; c2.method1(0); c2.method2(c2); system("PAUSE"); return EXIT_SUCCESS; } </code></pre> <p>Basically, C1 is an interface Class, therefore its methods are purely virtual. The proble am encountering is that Medhod2 passes and instance of the the class itself (which is class1 for the interface, and class2 for the class implementig such interface).</p> <p>Therefore Method2 has signature </p> <pre><code>void method2(class1&amp;) const; </code></pre> <p>in class1 and </p> <pre><code>void method2(class2&amp;) const; </code></pre> <p>in class2.</p> <p>This is the reason wihy I am getting the error below when compiling.</p> <pre><code>main.cpp: In function `int main(int, char**)': main.cpp:12: error: cannot declare variable `c2' to be of type `class2&lt;int&gt;' main.cpp:12: error: because the following virtual functions are abstract: Classes.h:14: error: void class1&lt;T1, T2&gt;::method2(class1&lt;T1, T2&gt;&amp;) const [with T1 = int, T2 = int] make: *** [main.o] Error 1 </code></pre> <p>How can I fix this issue?</p> <p>Can somebody please let me know? 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