Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing templates with C++
    primarykey
    data
    text
    <p>I am trying to implement a red black tree using templates. The insert function takes two generic types, Item and Key. However, when I'm creating an instance of the RedBlackTree in the main() and calling the function 'InsertKey', the program gives the error: Method 'InsertKey' could not be resolved. Also, I don't know what to pass as arguments in the 'InsertKey' function. I implemented an array which consists of random elements. The array should be one of the parameters, but I can't figure out what is the other parameter. </p> <p>This is my header file: </p> <pre><code>#ifndef REDBLACKTREE_H_ #define REDBLACKTREE_H_ template &lt;class Item, class Key&gt; class RedBlackTree { typedef enum { BLACK, RED }ColourNode; /* user data stored in tree */ typedef struct { int data; } treedata; typedef struct RBT { struct RBT *left; struct RBT *right; struct RBT *parent; struct RBT *root; ColourNode colour; //Item item; Key key; treedata data; }RBTNode; public: ~RedBlackTree(); // destructor RedBlackTree(Item, Key); // default constructor void InsertKey(const Item *&amp;, const Key *&amp;); void FixingInsert(const Item *&amp;, const Key *&amp;); int RemoveKey(Item, Key); int FindKey(Item, Key); //private: //RedBlackTree&lt;Item, Key&gt; *rootPointer; }; #endif /* REDBLACKTREE_H_ */ </code></pre> <p>This is my main()</p> <pre><code>#include &lt;iostream&gt; #include &lt;string&gt; #include &lt;time.h&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include "RedBlackTree.h" using namespace std; int main(int argc, const char* argv[]) { const int arraysize = 200; int arr[arraysize]; RedBlackTree&lt;int, int&gt; t1(int, int); srand((unsigned)time(0)); for(int i = 0; i &lt;= arraysize-1; i++) { arr[i] = rand() % 210; //printf("%d ", arr[i]); } for(int i = 0; i &lt;= arraysize-1; i++) { t1.InsertKey(arr[i], // something else//); //InsertKey should have another parameter, but for now I am trying to figure out why it cannot be resolved. } } </code></pre> <p>Also, any ideas of what the something else could be please? I can't figure out what to pass.</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