M
Mika Vainio
hi everybody,
i'm working on the following problem: i need to build a 26-nary tree to save
a data dictionary. every letter of the words is represented by a cell (cell
has a pointer-vector cell* children[26]). the last letter is a node
(node:cell, additional property "pagenr").
now: i understood the principals of polymorph objects and it worked fine
with the ususal examples. but in my case it does not! there is no
compilation or linking error and no error at runtime - at least not shown...
here's some code. maybe someone can give me some hints...
// Trie.cpp
//----------
(...)
void Trie::insert(char *word, int page)
{
// int value of first letter
int iword = ((int)word[0])-97;
insert_one(root->children[iword], word, page);
}
void Trie::insert_one(Cell* new_cell, char *word, int page)
{
if (new_cell == NULL) {
if (((int)word[1])-97 < 0) { // last letter
new_cell = new Node();
// new_cell->page = page;
}
else
new_cell = new Cell;
cout << typeid(new_cell).name() << " - ";
new_cell->display(); // virtual function in cell, cout pagenr in node
(...)
best regards,
mika
i'm working on the following problem: i need to build a 26-nary tree to save
a data dictionary. every letter of the words is represented by a cell (cell
has a pointer-vector cell* children[26]). the last letter is a node
(node:cell, additional property "pagenr").
now: i understood the principals of polymorph objects and it worked fine
with the ususal examples. but in my case it does not! there is no
compilation or linking error and no error at runtime - at least not shown...
here's some code. maybe someone can give me some hints...
// Trie.cpp
//----------
(...)
void Trie::insert(char *word, int page)
{
// int value of first letter
int iword = ((int)word[0])-97;
insert_one(root->children[iword], word, page);
}
void Trie::insert_one(Cell* new_cell, char *word, int page)
{
if (new_cell == NULL) {
if (((int)word[1])-97 < 0) { // last letter
new_cell = new Node();
// new_cell->page = page;
}
else
new_cell = new Cell;
cout << typeid(new_cell).name() << " - ";
new_cell->display(); // virtual function in cell, cout pagenr in node
(...)
best regards,
mika