Note that there are some explanatory texts on larger screens.

plurals
  1. POIssues with unordered_map
    primarykey
    data
    text
    <p>I'm trying to implement various data structures and algorithms for learning purposes.</p> <p>At the moment I'm trying to implement a Graph class template but I'm having issues with trying to use STL <code>unordered_map</code> (and <code>consequently priority_queue</code> in the future). </p> <p>Basically what happens at the moment is, for some reason, the template types don't match up when trying to initialize the vertex map within the graph. From what I understand, since I only plan to use key types from the native C++ types, as long as my value type is a pointer I shouldn't need to do any extra work apart from a copy constructor for my custom vertex class. The default comparer/hasher should suffice. But it doesn't and the error I'm receiving is kind of incomprehensible. </p> <p>The error:</p> <pre><code>Error 1 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::unordered_map&lt;T,graph&lt;T&gt;::vertex *,std::hash&lt;int&gt;,std::equal_to&lt;_Kty&gt;,std::allocator&lt;std::pair&lt;const _Kty,_Ty&gt;&gt;&gt;' (or there is no acceptable conversion) </code></pre> <p>The code:</p> <pre><code>#include "stdafx.h" #include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;unordered_map&gt; #include &lt;numeric&gt; #include &lt;functional&gt; using namespace std; class vertex; template &lt;class T&gt; class graph { public: graph() { verts = unordered_map&lt;T, vertex*&gt;(); } ~graph() { for each(auto v in verts) delete(v); delete(verts); } private: unordered_map&lt;T, vertex*&gt; verts; // --- Inner Classes --- struct path { vertex *dest; double cost; path(vertex *d = nullptr, double c = 0.0) : dest(d) : cost(c) {} inline int compare(const path&amp; p) { auto other = p.cost; return cost &lt; other ? -1 : cost &gt; other ? 1 : 0; } }; struct edge { vertex *dest; double cost; edge(vertex *d = nullptr, double c = 0.0) : dest(d) : cost(c) {} }; class vertex { public: // Vertex relationships T name; vector&lt;edge&gt;* adj; // Path Finding Information double distance; vertex *prev; int scratch; void reset_path_finding() { distance = double.infinity(); prev = nullptr; scratch = 0; } vertex(T name = default(T)) : name(name) : adj(new vector&lt;edge&gt;) : distance(double.infinity()) : prev(nullptr) : scratch(0) {} vertex(const vertex&amp; v) { name = v.name; adj = v.adj; distance = v.distance; prev = v.prev; scratch = v.scratch; } ~vertex() { delete(adj); } private: }; }; int main() { graph&lt;int&gt; myGraph = graph&lt;int&gt;(); cout &lt;&lt; "Press any key to continue..." &lt;&lt; endl; int x; cin &gt;&gt; x; return 0; } </code></pre>
    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