我想知道下面的 C++ 代码有什么问题。它在运行时崩溃。
#include <iostream.h>
#include <conio.h>
using namespace std;
class node
{
public:
int info;
node *addr;
node(){
info = 0;
addr = NULL;
}
~node(){}
};
void func(node *);
int main(void){
node *head;
node b;
b.info = 10;
*head = b;
func(head);
getch();
}
void func(node *obj){
cout<<"i: "<<(*obj).info;
}
最佳答案
*head = b;
不正确,因为 head 没有指向任何东西
head = &b ;
应该解决问题
关于c++ - 这段 C++ 代码有什么问题?它在运行时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13023956/