我很难理解为什么下面的代码不能在 Visual Studio 2012 下编译,错误已经嵌入到下面的代码中。我觉得这与引用堆栈对象有关,但不太确定。有人可以帮忙吗?
谢谢
#include <iostream>
typedef struct Node {
Node *next;
} Node;
void test(Node *&p) {
p=p->next;
}
void main() {
Node *p1=new Node();
test(p1); // this line compiles okay
Node p={0};
test(&p); // error C2664: 'test' : cannot convert parameter 1 from 'Node *' to 'Node *&'
}