0
#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);
}
위의 코드가 작동하지 않는 이유를 찾으려고합니다. munmap_chunk() : 나는 * 독방 감금 오류 또는 *이 glibc에 감지 ./a.out가 계속 유효하지 않은 포인터를 : 0x0000000001e46020 ***중첩 된 데이터 유형의 요소 추가
내가하는 벡터 또는 목록 인 "테이블"을 만드는 오전 기입. 각 단어와 줄 번호가 삽입 함수에 전달되면 항목 클래스에 추가해야합니다. ...
표의 요소 (목록)는 비어 있지 않습니까? – billz
네, 그럴 것 같아요. 그러나 그것을 고칠 수있는 방법이 확실하지 않습니다.'entry * insEntry = new entry; \t \t insEntry-> word = extrWord; \t insEntry-> lineNum.push_back (extrLineNum);'하지만 insEntry를 벡터에 추가하려면 어떻게해야합니까? –
그냥'push_back' 함수를 사용하십시오. 예 : 'table [index] .push_back (..)' – billz