allocating memory on memory already in use

I have a problem with a program I am writing in c++.

At a certain part of a program, when I use new to allocate memory to a pointer
TreeNode<T>* node;
node = new TreeNode<T>(newData);

for some reason it allocates a memory which is already being used by the program for a different purpose. What can cause such thing and how can I fix it?
What do you mean exactly by memory which is already being used?
I have in my project 2 binary trees. At a certain point, when the program executes the lines which I copied in the OP (which should allocate a new node for 1 of the trees), instead of allocating a new memory, it runs over the memory in which the root of the second tree is saved.

Basically, if the address of the root of the second tree is 1, the "node = new TreeNode<T>(newData);" saves the new node also in address 1.
Topic archived. No new replies allowed.