Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is very clean code :). Welcome to C++!</p> <p>I believe what you want to do is use a template variable to hold your edge weights. How about something like the following:</p> <pre><code>using std::swap; template&lt;class Distance&gt; class Node { friend void swap(Node &amp; first, Node &amp; second) { swap(first.name, second.name); } public: Node(std::string val); Node(const Node &amp; copy); Node &amp; operator = (Node copy) { swap(*this, copy); return *this; } bool operator &lt; (Node &amp; rhs) const { return (size &lt; rhs.size); } bool operator &gt; (Node &amp; rhs) const { return (size &gt; rhs.size); } bool insertEdge(Node * dest, Distance distToNode); // I'd like for this return type to not be tied to an int // Especially if weights were represented as floats or doubles Distance findTravelDistance(Node * const &amp; toNode) const; Distance findTravelDistance(std::queue&lt;Node *&gt; * const &amp; nodeRoute) const; // Mutators void setNodeName(const std::string nameToSet); std::string getNodeName() const; void setNodeSize(const Distance size); int getNodeSize() const; // Misc void toString() const; // Constants static const bool ALLOW_CIRCULAR; ~Node(); private: int size; std::string name; std::map&lt;Node *, Distance&gt; * travelEdges; }; // end class </code></pre> <p>As a bonus, I've moved your using declarations to the top of the class. Generally these go at the top of the file. You also might benefit from taking a look at the holy scripture that is the Parashift C++ FAQ, particularly the <a href="http://www.parashift.com/c++-faq/const-correctness.html" rel="nofollow">section on const correctness</a>. Your comparator methods, for example, should have const Node&amp; parameters.</p>
 

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