Note that there are some explanatory texts on larger screens.

plurals
  1. POCompilation issue with functions with template parameters
    text
    copied! <p>Hi all, I have a compilation error I can't seem to get through. </p> <p>Here's what I do: I declare an object of class2, and I call its function "function2". This function, in turn, declares an object of class1 and calls its function "function1". Right now, this code gets a compilation error at that point ("function1" can't be properly called):</p> <p>error: expected primary-expression before ‘)’ token</p> <p>However, if I uncomment the useless "function1", then the code compiles. I find this confusing, because this is <em>not</em> the function being called, and should not affect at all.</p> <pre class="lang-c prettyprint-override"><code>#include &lt;iostream&gt; using namespace std; template&lt;int parameter1&gt; class class1 { public: template &lt; int parameter2 &gt; void function1() { cout &lt;&lt; "We do useful things here" &lt;&lt; endl; } }; template &lt; int parameter3 &gt; class class2 { public: //template &lt; char a, char b &gt; bool function1() { // cout &lt;&lt; "Useless definition (?)" &lt;&lt; endl; //} void function2() { class1 &lt; parameter3 &gt; an_instance_of_class1; an_instance_of_class1.function1 &lt; 999 &gt; (); } }; int main(int argc, char** argv) { class2 &lt; 99 &gt; an_instance_of_class2; an_instance_of_class2.function2(); } </code></pre> <p>Does anyone know what I'm missing? Thanks in advance.</p> <p>Compiler version:</p> <pre class="lang-c prettyprint-override"><code>$ g++ --version g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 </code></pre>
 

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