创建简单链表时出错。
错误消息是 cannot convert 'listNode**' to 'listNode*' in assignment
。
代码:
struct listNode {
const char *data;
listNode *link;
};
int main(){
listNode *node = new listNode;
node->data = "Adley";
node->link = NULL;
listNode *node2 = new listNode;
node2->data = "Bert";
node2->link = NULL;
listNode *node3 = new listNode;
node3->data = "Colin";
node3->link = NULL;
node->link = &node2;
node2->link = &node3;
for(listNode *i = &node; i != NULL; i = i->link){
std::cout << i->data << std::endl;
}
return 0;
}
我知道这个问题很容易解决,但很抱歉我的大脑现在很困惑。
最佳答案
变化:
node->link = &node2;
node2->link = &node3;
收件人:
node->link = node2;
node2->link = node3;
删除与号 (&)。 node2
和 node3
已经是指针。无需指向指针:)
关于c++ - 无法在赋值中将 'listNode**' 转换为 'listNode*',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25835396/