#include <iostream>
#include <list>
#include <vector>
#include <fstream>
using namespace std;
class index_table
{
public:
index_table();
void insert(string, int);
void find();
private:
class entry
{
public:
string word;
vector<int> lineNum;
};
vector<list<entry> > table;
};
index_table::index_table()
{
table.resize(128);
}
void index_table::insert(string extrWord, int extrLineNum)
{
int index = extrWord[0];
list<entry>::iterator itor = table[index].begin();
itor->word = extrWord; //why doesnt this work???
itor->lineNum.push_back(extrLineNum);
}
我试图找出上述代码无效的原因。我一直遇到seg错误或 * glibc检测到* ./a.out:munmap_chunk():无效指针:0x0000000001e46020 ***
我正在创建一个&#34;表&#34;这是一个矢量或列表是一个条目。将每个单词和行号传递给insert函数后,需要将其添加到条目类...
答案 0 :(得分:0)
int index = extrWord[0];
entry insEntry;
insEntry.word = extrWord;
insEntry.lineNum.push_back(extrLineNum);
table[index].push_back(insEntry)