Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
hi,
I'm creating a binary search tree.

class code:
C++
class bstnode{

private:
	int key;
	bstnode *left;
	bstnode *right;

public:
	//bstnode
	bstnode()
		{key=-1; left=0; right=0;}
//set right
	void set_right(bstnode *r)
		{right = r;}


main code:
C++
//declare a bstnode
bstnode(node2);

//set right of node
	node.set_right(node2);


i get erreor below:

IntelliSense: no suitable conversion function from "bstnode" to "bstnode *" exists

how can i solve it?

Thank you,
Posted
Comments
nv3 5-Jun-13 16:54pm    
The second line of your main code is either incomplete or not correct. Did you want to say:
bstnode node;
And in line 5 you probably wanted to write:
node.set_right (&node2);
m.r.m.40 5-Jun-13 16:59pm    
when i do as you said,
when i print node.right, it gives me the address of node2 not the key of it.

1 solution

You should provide a pointer to (that is the address of) bstnode object as (the only) argument to set_right method (while you are passing the object itself), change from
Quote:
node.set_right(node2);
to
node.set_right(&node2);





Please note:
Quote:
//declare a bstnode
bstnode(node2);
is not a valid C++ variable declaration, change to
C++
bstnode node2;
 
Share this answer
 
Comments
m.r.m.40 5-Jun-13 16:55pm    
i did it,
when i printed node.right
it gave me the address of node.right not the key of node2
how can i see the key of node2 ?
thank you,
CPallini 5-Jun-13 16:59pm    
node.right->key
m.r.m.40 5-Jun-13 17:02pm    
thank you CPallini,
i didn't know about "->" expression.
what is its name(i want to search and learn about it)
CPallini 5-Jun-13 17:16pm    
It is the 'arrow operator'.
Sergey Alexandrovich Kryukov 5-Jun-13 20:07pm    
Sure, a 5.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900