【发布时间】:2014-03-14 14:35:09
【问题描述】:
我正在学习 cpp,需要一些帮助。
我的代码不起作用,它停在add->value = value。
typedef struct node node;
struct node{
int value;
struct node *next;
};
node *top;
int insert(int value){
struct node *add;
cout<< "here it stops";
add->value = value;
add->next = NULL;
if(top == NULL ){
top == add;
}else{
add->next = top;
top = add;
}
}
【问题讨论】:
-
add没有初始化,所以它没有指向任何地方。 -
你确定那是 C++ 吗?对我来说它看起来像 C。
-
对于C++,不需要typedef,声明时也不需要重复
struct。如果您要学习“C++ 作为更好的 C”,请使用其中的好处。 -
作为参考,下次包括编译器抛出的错误/警告(或者提到它没有发出任何如果是这种情况)。
标签: c++ pointers memory-management