C++ 编译时错误:无法转换';节点*(int)和#x27;至';节点*';
我犯了这个错误,我想不出背后有什么好的理由。C++ 编译时错误:无法转换';节点*(int)和#x27;至';节点*';,c++,C++,我犯了这个错误,我想不出背后有什么好的理由。 帮帮我。 我已经试过了,但不能接受 这是我的密码: #include<iostream> using namespace std; struct node{ int data; node *left; node *right; }; node* insert(node* root, int data); node* getnewnode(int data); int main() { node *r
帮帮我。
我已经试过了,但不能接受 这是我的密码:
#include<iostream>
using namespace std;
struct node{
int data;
node *left;
node *right;
};
node* insert(node* root, int data);
node* getnewnode(int data);
int main()
{
node *root;
root= NULL;
root=insert(root,12);
cout<<root->data;
root=insert(root,22);
cout<<root->data;
root=insert(root,32);
cout<<root->data;
root=insert(root,62);
cout<<root->data;
root=insert(root,72);
cout<<root->data;
root=insert(root,90);
cout<<root->data;
root=insert(root,125);
cout<<root->data;
root=insert(root,15);
cout<<root->data;
}
node* getnewnode(int data)
{
node* newnode = new newnode();
(*newnode).data=data;
(*newnode).left=(*newnode).right=NULL;
return newnode;
}
node* insert(node* root, int data)
{
if(root==NULL)
root = getnewnode();
else if(data<(*root).data)
(*root).left=insert((*root).left,data);
else
(*root).right=insert((*root).right,data);
return root;
}
此行
root=getnewnode代码>尝试将函数分配给int
变量
要调用函数,请使用括号:root=getnewnode(数据)
@MarkSetchell编译时错误?getnewnode()
函数中的node*newnode=newnewnode()
非常可疑。您描述了来自编译器的所有错误消息,还是仅描述了最后一个错误消息?getnewnode
获取一个参数,您没有给出任何信息,请参阅我的答案以获得正确信息line@Peter他首先编写justroot=getnewnode代码>,我告诉他用括号写,所以他只用括号编辑。。。现在他忘了参数是的,好的。代码中存在多个错误,并在有人指出其中一个错误时不断编辑问题。使问题变得无用,因为答案将过时。因此,我投票赞成结束这个问题(本质上,问题是粗心的编码和打字错误)。我已经更正了括号,仍然得到了与分配相关的prblm。@karan_13查看您的编辑,您已经忘记了参数getnewnode
获取一个参数,因此必须为其指定一个参数。在您的情况下,此参数是数据
谢谢@Garf365,对于这个愚蠢的错误,我深表歉意。
When I compile it, I got this error:
>prog.cpp: In function 'node* insert(node*, int)':
prog.cpp:48:14: error: cannot convert 'node*(int)' to 'node*' in assignment
root = getnewnode;