我目前正在获得一个seg错误,并且它从我认为是main中的一行开始,在gdb中进行回溯之后,我基本上可以找到它,但我不确定需要改变什么.这是我按顺序看到的地方:
首先是主要:
DeckOps *deck = new DeckOps(filename);
Run Code Online (Sandbox Code Playgroud)
我相信是导致它的线,回溯也包括
class DeckOps{
public:
DeckOps(string filename);
~DeckOps();
private:
dlist *deck;
}
Run Code Online (Sandbox Code Playgroud)
然后是.cpp文件
DeckOps::DeckOps(string filename){
ifstream inF;
inF.open(filename.c_str());
if (inF.fail()){
cerr << "Error opening file" << endl;
exit(1);
}
int deckcount = 28;
int card;
for(int i = 0; i <= deckcount; i++){
inF >> card;
deck->insertRear(card);
}
inF.close();
}
Run Code Online (Sandbox Code Playgroud)
然后最后是最后一个地方
void dlist::insertRear(int d){
LinkNode *link = new LinkNode();
int *nd = new int();
*nd = d;
link->data= nd;
if(first == 0){
first = …Run Code Online (Sandbox Code Playgroud)