c++编译可以通过,运行的时候崩溃,运行到setCustom函数,this值为NULL,str输入值正常
class GooseStatInfo {
private:
std::string _custom;
public:
void setCustom(const std::string& str) {
_custom = str;
//debug 编译到此处str为字符串,this 值为NULL
}
std::string getToString() {
Serial gs;
gs.update(_custom);
// ... other codes
}
};
class ABRInt {
private:
GooseStatInfo* _stat;
ABRInt(ABRConfig& config, StatInfo* s) {
_stat = s;
// ... other codes
}
void onEvent(const std::shared_ptr<ABREvent>& event) {
std::string results = ABRCustC::getStatInfo();
//需要把results的结果发到_custom,ABRCustC::getStatInfo()返回的结果为str类型,做了c.str()处理
_stat->setCustom(results);
// ... other codes
}
};
编译输出
编译语法没有错误