在检查指针是否为0时,我遇到了这个恼人的分段错误。这是有问题的代码:
bool egammaMVACalib::checkTree()
{
// Not a TChain
cout << "a" << endl;
assert(m_tree); // crash on line 751 (this one)
cout << "B" << endl;
m_tree
是egammaMVACalib
类型TTree*
的数据成员,所以我真的不明白为什么assert(m_tree)
会引起细分违规。这是堆栈跟踪的输出
a
19:07:25 30574 Wrk-0.9 | *** Break ***: segmentation violation
===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0 0x000000361869a4d5 in waitpid () from /lib64/libc.so.6
#1 0x000000361863c481 in do_system () from /lib64/libc.so.6
#2 0x00002ac5099cb322 in TUnixSystem::StackTrace() ()
from /usr/local/proof/root/lib/libCore.so
#3 0x00002ac5099c7fea in TUnixSystem::DispatchSignals(ESignals) ()
from /usr/local/proof/root/lib/libCore.so
#4 <signal handler called>
#5 egammaMVACalib::checkTree (this=0x0) at ../Root/egammaMVACalib.cxx:751
#6 0x00002ac5117e5563 in egammaMVACalib::LoadVariables (this=0x1, index=0)
at ../Root/egammaMVACalib.cxx:492
答案 0 :(得分:8)
如果你看第5帧,你的this
指针为空。这意味着问题从那里开始。断言中的段错误仅仅是对它的重新诠释!
答案 1 :(得分:2)
线索在这里:
#5 egammaMVACalib::checkTree (this=0x0) at ../Root/egammaMVACalib.cxx:751
this = 0表示您的对象为空