0

I am stuck on something that I know is so simple that I can't figure it out...

I have a BST class, and a private item:

Node<K> *root; 	// root pointer


//and in a seperate class I have...
template <typename K>
class Node 
{
  public:

    // constructors
    Node() {};
    Node(const K newKey, Node<K> *l, Node<K> *r)
	:key(newKey), left(l), right(r) {};

    // data members
    K		key;	// key is a template
    Node<K> *   left;	// points to left child or NULL
    Node<K> *   right;	// points to right child or NULL
};

//cut&paste some code
Node<K> n;
n.key = newKey;
n.left = NULL;
n.right = NULL;
//so obviously there is a lot of cut&paste going on, but I assure you everything above this line works just fine.
root = &n;

Any help is greatly appreciated!!! After a certain point I tried every combination of &* that I could think of, ie: root = *n; *root=n; *root=&n; *root=*n; ... etc, you get the point!

Any help is greatly appreciated!!!

4
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by bugmenot
0

You have created Node<K> *root; before defining the class Node. Declare it after the class. Furthermore I dont think you can use Node<K> n; outside the class. You will have to specify a valid class or datatype instead of template K like Node<int> n;

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.