Re: polymorph object - why doesn't it work???
From: Mika Vainio (mika-spamblock_at_vainio.de)
Date: 04/26/04
- Next message: Karthik: "Re: polymorph object - why doesn't it work???"
- Previous message: Stephen Waits: "Re: protecting my char*"
- In reply to: Karthik: "Re: polymorph object - why doesn't it work???"
- Next in thread: Karthik: "Re: polymorph object - why doesn't it work???"
- Reply: Karthik: "Re: polymorph object - why doesn't it work???"
- Reply: Uwe Schnitker: "Re: polymorph object - why doesn't it work???"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 26 Apr 2004 01:03:32 +0200
hi karthik,
yes, i have my own display() implementation (cout << "Pagenr: " <<
new_cell->page << endl;). and here are all my header files.
best regards,
mika
// Cell.h
//-----------------
class Cell {
public:
Cell() {}
virtual ~Cell();
virtual void display() const;
char letter;
Cell* children[26];
};
// Node.h
//----------------
class Node : public Cell {
public:
Node() {}
int page;
void display();
Node* children[26];
};
// Trie.h
//----------------------------------
#include "Node.h"
class Trie {
public:
Trie() {
root = NULL;
root = new Cell;
for (int i = 0; i<26; i++)
root->children[i] = NULL;
// root->page = 1;
root->letter = '\0';
}
void display();
void insert(char*, int);
int search(char*);
void erase(char*);
private:
Cell *root;
char *word;
void insert_one(Cell* new_cell, char *word, int page);
void display_one(Cell *top, char* prefix);
int search_one(Cell *&new_cell, char *word);
void erase_one(Cell *&new_cell, char *word);
};
"Karthik" <removeme_kaykaydreamz@yahoo.com> schrieb im Newsbeitrag
news:408c2f40$1@darkstar...
> Mika Vainio wrote:
>
> > 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;
> Try using macros instead of constants, as in 97 here.
> >
> > 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
> > (...)
> Do you have your own implementation of display function in 'Node'
> class. It would be nice if you can mention the class hierarchy clearly
> out here to understand things better.
>
> >
> > best regards,
> > mika
> >
> >
>
>
> --
> Karthik
>
> ------
>
> Human Beings please 'removeme' for my email.
- Next message: Karthik: "Re: polymorph object - why doesn't it work???"
- Previous message: Stephen Waits: "Re: protecting my char*"
- In reply to: Karthik: "Re: polymorph object - why doesn't it work???"
- Next in thread: Karthik: "Re: polymorph object - why doesn't it work???"
- Reply: Karthik: "Re: polymorph object - why doesn't it work???"
- Reply: Uwe Schnitker: "Re: polymorph object - why doesn't it work???"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|