Error C2440: Cannot convert from "node *" to "node"

Hello

I'm trying to create a binary tree. However, everytime I try to create a node object, the compiler gives me an error. Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class node
{
	public:
	node* left;
	node* right;
	node* root_;
	int value;

	node(int num, node* root)
	{
		value = num;
		left = right = NULL;
		root_ = root;
	}

	~node()
	{
		delete left;
		delete right;
		delete root_;
	}
}


1
2
3
4
5
int main()
{
	node root = new node(10, NULL);
	return 0;
}


If I replace in the main function the code "node root = new code(10, NULL);" with "node* root = new code(10, NULL);" the error goes away. However, I don't want to create a new pointer, but an object. What am I doing wrong?

Regards,
node root(10, NULL);
Operator new returns a pointer. So you shall write

node *root = new node(10, NULL);

Ah yes, I got it mixed up. Thanks to both of you.
Topic archived. No new replies allowed.