Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the meaning of this 'missing template arguments' C++ error
    primarykey
    data
    text
    <p>Ahh, C++ templates... </p> <blockquote> <p>The code I see,<br> makes sense to me,<br> but GCC...<br> it disagrees.</p> </blockquote> <p>The following code compiles and runs as expected, but if you uncomment that <code>#define</code>, you get the error, which I don't understand. The symbol <code>iterator</code> still has only one thing it can refer to: the typedef in the superclass. So I guess I have two questions: 1. What do the errors mean? 2. What is the best way to fix them.</p> <pre><code>#include &lt;map&gt; #include &lt;string&gt; #include &lt;cstdio&gt; using namespace std; // #define WITH_TEMPLATE 1 #ifdef WITH_TEMPLATE template &lt;class C&gt; struct MyClass : public map&lt;string, C&gt; #else struct MyClass : public map&lt;string, int&gt; #endif { bool haskey(const string &amp;s) { iterator it = find(s); return (it != end()); } }; int main() { #ifdef WITH_TEMPLATE MyClass&lt;int&gt; m; #else MyClass m; #endif m["test"] = 10; printf("%d %d\n", m.haskey("test"), m.haskey("no")); } </code></pre> <p>Errors from GCC:</p> <blockquote> <p>temp.cc: In member function ‘bool MyClass::haskey(const std::string&amp;)’:<br> temp.cc:18: error: <strong>missing template arguments before ‘it’</strong><br> temp.cc:18: error: expected `;' before ‘it’<br> temp.cc:19: error: ‘it’ was not declared in this scope<br> temp.cc:19: error: <strong>there are no arguments to ‘end’ that depend on a template parameter, so a declaration of ‘end’ must be available</strong><br> temp.cc:19: error: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated) </p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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