Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well... basically you are calling non-existing function. When you use <code>get_key(xPtr)</code> inside a BST you are calling <code>BSD::get_key(Node*)</code>. You are allowed to call <code>Node::get_key(Node*)</code> but since it's not a static function (which you'd call by <code>Node::get_key(xPtr)</code>) you have to use the object:</p> <pre><code>if (key &lt; xPtr-&gt;get_key(xPtr)) </code></pre> <p>If you wanted to use it like:</p> <pre><code>Node::get_key(xPtr) </code></pre> <p>you have to mark <code>Node::get_key(Node*)</code> as <code>static</code>:</p> <pre><code>// Node.h class BST; class Node { string m_key; string m_data; Node *m_left; Node *m_right; public: Node(string key, string data) : m_key(key), m_data(data) {} ~Node(); static string get_key(Node *ptr); static string get_data(Node *ptr); static Node* get_left(Node *ptr); static Node* get_right(Node *ptr); }; </code></pre> <p>but even better would be:</p> <pre><code>// Node.h class BST; class Node { string m_key; string m_data; Node *m_left; Node *m_right; public: Node(string key, string data) : m_key(key), m_data(data) {} ~Node(); string get_key(); string get_data(); Node* get_left(); Node* get_right(); }; </code></pre> <p>and:</p> <pre><code>// BSD.cpp string Node::get_key() { return m_key; } string Node::get_data() { return m_data; } Node* Node::get_left() { return m_left; } Node* Node::get_right() { return m_right; } </code></pre> <p>Then you'd be able to use it like this:</p> <pre><code>void BST::insert(string key, string data) { Node* yPtr = NULL; Node* xPtr = m_root; while (xPtr != NULL) { yPtr = xPtr; if (key &lt; xPtr-&gt;get_key()) { // actual object-oriented programming } } } </code></pre> <p>On a side note: don't use <code>using namespace std</code> in header to declare its usage globally - it's not a good thing to 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. 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