Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding specialized functionality to STL containers
    primarykey
    data
    text
    <p>I have a very special scenario, and I'm trying to add functionality to "list"...</p> <pre><code>#include &lt;list&gt; template &lt;typename T&gt; class ShortList : public std::list&lt;T&gt; { private: unsigned short max_items; public: // Getter and setter methods unsigned short getMaxItems (void) { return this.max_items; } void setMaxItems (unsigned short max_items) { this.max_items = max_items; return; } // Work methods void insertItemSorted (T item) { std::list&lt;T&gt;::iterator i, e = this.short_list.end(); // Insertion sort O(n*max_items) for ( i = this.short_list.begin() ; i != e ; ++i ) { // Insert if smaller if ( item.getDiff() &lt; (*i).getDiff() ) { this.short_list.insert(i, item); // Restrict list size to max items if ( this.short_list.size() &gt; this.max_items ) { this.short_list.erase(this.short_list.end()); } } } return; } } </code></pre> <p>I can't understand what I'm doing wrong here. Here are my compile errors...</p> <pre class="lang-none prettyprint-override"><code>ShortList.cpp: In member function 'int ShortList&lt;T&gt;::insertItemSorted(T)': ShortList.cpp:21: error: expected `;' before 'i' ShortList.cpp:24: error: 'i' was not declared in this scope ShortList.cpp:24: error: 'e' was not declared in this scope ShortList.cpp: At global scope: ShortList.cpp:35: error: expected unqualified-id at end of input </code></pre> <p>I feel as though I'm following a C++ tutorial to the letter. Can anyone explain where I've gone wrong? I know it's poor form to extend the functionality of a STL container, but this a is purely a scholarly pursuit.</p>
    singulars
    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