Note that there are some explanatory texts on larger screens.

plurals
  1. POError when resizing vector of template object
    text
    copied!<p>I am trying to create a vector of vector of a template object. The error occurs when I try to resize the inner vector and I can't make heads or tail of the error message. I don't know where it gets the HashTable::Item::Item from. Any suggestions?</p> <blockquote> <p>/usr/include/c++/4.4.6/bits/stl_vector.h(552): error: no instance of constructor "HashTable::Item::Item [with Key=int, Value=Varvalue]" matches the argument list resize(size_type __new_size, value_type __x = value_type())</p> <pre><code> detected during: instantiation of "void std::vector&lt;_Tp, _Alloc&gt;::resize(std::vector&lt;_Tp, _Alloc&gt;::size_type={size_t={unsigned long}}, std::vector&lt;_Tp, _Alloc&gt;::value_type) [with _Tp=HashTable&lt;int, Varvalue&gt;::Item, _Alloc=std::allocator&lt;HashTable&lt;int, Varvalue&gt;::Item&gt;]" at line 118 of "main.cc" </code></pre> </blockquote> <p>Here is the relevant code:</p> <p><pre>#define VECLEN 16 class Varvalue { public: char data[32]; };</p> <p>template class HashTable { private: class Item { public: bool valid; Key key; Value value; Item *next;<br> Item(const Key k, const Value v, Item *b = 0, bool val = true): key(k), value(v), next(b), valid(val) {} };</p> <pre><code>vector&lt;vector&lt;Item&gt; &gt; table; int tableSize; HashTable(const int s): tableSize(s) { table.resize(tableSize); for(int i=0; i&lt;table.size(); i++) table[i].resize(VECLEN); // &lt;&lt;-- error line 118 } </code></pre> <p>}</p> <code>int main() { HashTable&lt;int, Varvalue&gt; htable(nkeys); } </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