当我运行我的程序时,我得到了 Segmentation Fault 错误。我相信它来自我如何使用在类定义中私下声明的数组“string *words”。我在 .cpp 文件中使用它,有人知道我需要更改什么吗?继承人我认为问题出在的功能:
Dictionary::Dictionary(string filename){
ifstream inF;
inF.open(filename.c_str());
if (inF.fail()){
cerr << "Error opening file" <<endl;
exit(1);
}
inF >> numwords;
numwords = 3000;
words = new string(words[numwords]);
for(int i=0; i <= numwords - 1; i++){
inF >> words[i];
}
inF.close();
}