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!!!

Recommended Answers

All 3 Replies

Isnt it working with

*root=n;// As this is a normal code for pointing to a variable?

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;

how about

root = new Node<K>(newKey, NULL, NULL);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.