I am having difficulty understanding why below code does not compile under Visual Studio 2012, error already embedded in below code. I feel it has something to do with referencing stack object, but not quite sure. Can someone help?
Thanks
#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 *&' }