1.core dumped
出现
空指针
引起的core dumped
具体代码如下
class NVariableDeclaration : public NStatement{
public:
const NIdentifier &type;
NIdentifier &id;
NExpression *assignmentExpr;
NVariableDeclaration(const NIdentifier &type, NIdentifier &id) : type(type), id(id) {}
NVariableDeclaration(const NIdentifier &type, NIdentifier &id, NExpression *assignmentExpr) : type(type), id(id), assignmentExpr(assignmentExpr) {
}
void debug()
{
std::cout << type.name <<"\t";
id.debug();
assignmentExpr->debug(); //还真是这里的问题... 我需要rust的Option的Debug
std::cout <<std::endl;
}
};
当调用assignmentExpr->debug();
的时候, 如果指针为NULL, 完蛋, 产生段错误
解决
debug()函数<