Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to write my own iterator based on an STL iterator
    primarykey
    data
    text
    <p>I have a little problem while trying to implement a container, Set, based on a linked list. Yeah, I know that there's an STL implementation of a set, but this is for homework. :)</p> <p>So, this is what I have done so far:</p> <p>my Set.h file looks like that:</p> <pre><code>template &lt;class T&gt; class Set { private: typedef std::list&lt;T&gt; base_container; base_container items; public: class myIterator { public: typename base_container::iterator base_iterator; myIterator() { } }; void addItem(const T item) { items.push_back(item); } typedef typename Set&lt;T&gt;::myIterator setIterator; setIterator begin() { return items.begin(); } setIterator end() { return items.end(); } Set&lt;T&gt;(void) { } ~Set&lt;T&gt;(void) { } }; </code></pre> <p>Now, main.cpp:</p> <pre><code>#include "Set.h" int main(void) { Set&lt;int&gt; mySet; mySet.addItem(1); mySet.addItem(2); mySet.addItem(3); mySet.addItem(4); Set&lt;int&gt;::myIterator x; x = mySet.begin(); // produces an error about non-convertible types. return EXIT_SUCCESS; } </code></pre> <p>The error is as follows:</p> <pre><code>error C2664: 'Set&lt;T&gt;::myIterator::myIterator(const Set&lt;T&gt;::myIterator &amp;)' : cannot convert parameter 1 from 'std::_List_iterator&lt;_Mylist&gt;' to 'const Set&lt;T&gt;::myIterator &amp;' </code></pre> <p>Clearly I messed things up, but I'm not sure which part of the code is actually the problem. Any suggestions about how to fix this? Any helpful information will be appreciated.</p> <p>Thanks. :)</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