Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The first problem is that you use the nested class <code>graph::vertex</code> before declaring it. Further confusion is caused because you've declared <code>class vertex</code> <em>outside</em> <code>graph</code>, so the compiler initially thinks you mean that class. You could declare <code>vertex</code> near the start of <code>graph</code>:</p> <pre><code>template &lt;class T&gt; class graph { class vertex; private: // and so on }; </code></pre> <p>There are several other syntax errors, which should be obvious if you look at the lines referred to by the error messages. The syntax for a range-based for loop is</p> <pre><code>for (auto v : verts) // not for each(auto v in verts) </code></pre> <p>This gives you key-value pairs, so to delete the <code>vertex</code>, you need</p> <pre><code>delete v.second; </code></pre> <p>Better still, change <code>verts</code> into <code>unordered_map&lt;T, vertex&gt;</code>, containing objects rather than pointers, and it will manage all its memory automatically - you won't need a destructor at all.</p> <p>The syntax for a value-initialised temporary is</p> <pre><code>T() // not default(T) </code></pre> <p>Clauses in a constructor's initialiser list are separated by commas, not colons:</p> <pre><code>path(vertex *d = nullptr, double c = 0.0) : dest(d) , cost(c) {} ^ not : </code></pre> <p>A <code>double</code> with infinite value is</p> <pre><code>std::numeric_limits&lt;double&gt;::infinity() // not double.infinity() </code></pre> <p>for which you need to in include <code>&lt;limits&gt;</code>.</p> <p><code>verts</code> doesn't need deleting in the destructor, since you don't <code>new</code> it. Nor does it need assigning from a default-constructed temporary in the constructor, since it's just been default-constructed.</p> <p>There are a few places where you are making life difficult for yourself through unnecessary use of pointers and <code>new</code>. Try to avoid <code>new</code> except when you really need it; and learn about <a href="http://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization" rel="nofollow">RAII</a>, especially the use of smart pointers and containers, for when you do.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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