Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to import std::less<T> as a typename?
    text
    copied!<p>I have the following code in Sol.h with most omitted due to school rules:</p> <pre><code>template &lt;typename T,int promote = 1, typename compare = std::less&lt;T&gt;() &gt; class Sol{ private: struct node{ T data; struct node *next; struct node *previous; }; node *head, *tail; public: typedef unsigned int size_type; typedef T key_type; typedef T value_type; size_type count; Sol() : head(0), tail(0) { count=0; } </code></pre> <p>Basicly it is a container similar to vector but it does some things that we are required to template. I can't seem to get the "typename compare = std::less&lt; T>" -ignore the space.</p> <p>When I compile with the test code I get two errors from Sol.h and the rest all relate to them.</p> <pre><code>&gt;temple&gt; g++ -Wall -Wextra -ansi -pedantic Sol.h main.cc Sol.h:6:61: error: expected type-specifier Sol.h:6:61: error: expected '&gt;' main.cc: In function 'int main()': main.cc:19:19: error: template argument 3 is invalid main.cc:19:24: error: invalid type in declaration before '(' token main.cc:19:48: error: expression list treated as compound expression in initializer [-fpermissive] main.cc:19:48: warning: left operand of comma operator has no effect [-Wunused-value] main.cc:19:48: error: invalid conversion from 'char*' to 'int' [-fpermissive] main.cc:20:19: error: template argument 3 is invalid main.cc:20:31: error: expected initializer before 'it' main.cc:22:13: error: request for member 'erase' in 'foo', which is of non-class type 'int' main.cc:24:9: error: 'it' was not declared in this scope main.cc:24:18: error: request for member 'find' in 'foo', which is of non-class type 'int' main.cc:25:9: error: request for member 'end' in 'foo', which is of non-class type 'int' main.cc:28:13: error: request for member 'find' in 'foo', which is of non-class type 'int' main.cc:30:13: error: request for member 'find' in 'foo', which is of non-class type 'int' main.cc: In function 'std::string cat(const T&amp;) [with T = int, std::string = std::basic_string&lt;char&gt;]': main.cc:23:24: instantiated from here main.cc:12:35: error: 'int' is not a class, struct, or union type main.cc:12:50: error: request for member 'end' in 'con', which is of non-class type 'const int' main.cc:12:35: error: 'int' is not a class, struct, or union type main.cc:12:35: error: 'int' is not a class, struct, or union type main.cc:12:35: error: 'int' is not a class, struct, or union type </code></pre> <p>To be clear line 6 is the template line.</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