类函数调用。 [英] class function call.
问题描述
我正在创建一个二叉搜索树。
类代码:
< pre lang =c ++> class bstnode {
private :
int 键;
bstnode * left;
bstnode * right;
public :
// bstnode
bstnode()
{key = - 1 ; left = 0 ; right = 0 ;}
// set正确
void set_right(bstnode * r)
{right = r;}
主要代码:
// 声明bstnode
bstnode(node2);
// 设置节点权限
node.set_right( node2);
i下面的错误:
智能感知:不合适转换功能从bstnode到bstnode *存在
如何解决?
谢谢你,
你应该提供指向的指针(即 的地址)bstnode
对象为set_right
方法(唯一的)参数(当你传递对象本身时),改为
Quote:node.set_right(node2);
to
node.set_right(& node2);
请注意:
引用://声明一个bstnode
bstnode(node2);不是有效的
C ++
变量声明,更改为
bstnode node2;
hi,
I'm creating a binary search tree.
class code:
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:
//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,
You should provide a pointer to (that is the address of)bstnode
object as (the only) argument toset_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
bstnode node2;
这篇关于类函数调用。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!