当我运行我的代码(它是用root编写的,这是基于c ++的编程语言)时,要么它给了我分段错误,要么它停留在某一点,但我无法弄清楚它为什么会发生。以下是我的代码的详细信息。
DataArray* g[MaxNumbersOfDetDir];
for(Int_t i=0; i<MaxNumbersOfDetDir; i++)
{
if (testCout)cout<<"test"<<endl;
g[i] = new DataArray((const int)PossibleHits[i]);
if (testCout)cout<<"Possible hits = "<<PossibleHits[i]<<"\t g[i] = "<<g[i]<<endl;
}
此DataArray类定义为
//Constructor with number of elements to allocate
DataArray::DataArray(const int maxNumOfChannels)
: TObject(), nallocated(0), nch(0), ch(0)
{
if (COUT)cout<<"in Dataarray cpp 11"<<endl;
if (maxNumOfChannels > 0)
{
if (COUT)cout<<"in Dataarray cpp 22 = "<<maxNumOfChannels<<endl;
ch = new chtype[maxNumOfChannels];
if (COUT)cout<<"in Dataarray cpp 22 ch = "<<ch<<endl;
nallocated = maxNumOfChannels;
if (COUT){ std::cout << "New object with " << nallocated
<< " elements. "<<ch<<"\t Object at "
<< (this) << std::endl; }
};
}
所以,我的代码停在
行 ch = new chtype[maxNumOfChannels];
提供的信息是否充足,还是应该提供更多信息?