Re: polymorph object - why doesn't it work???

From: Mika Vainio (mika-spamblock_at_vainio.de)
Date: 04/26/04


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.



Relevant Pages

  • [PATCH 2/2] display: Driver ks0108 and cfag12864b
    ... Adds support for additional "display" devices, ... +static const unsigned int FirstMinor = 0; ... +void cfag12864b_E(unsigned char _State) ... +void cfag12864b_CS1 ...
    (Linux-Kernel)
  • Re: display array in a frame wnd
    ... Some display are corresponding to several cameras (global ... void CDisplayImg::DrawToHDC ... void CDisplayImg::FillBitmapInfo(BITMAPINFO* bmi, int width, int height, ... int bpp, int origin) ...
    (microsoft.public.vc.mfc)
  • Cone display
    ... display but I cannot get this to work could someone explain to me how ... void display ... void reshape(int w, int h) ... void ExtractCommandLineParameters(int argc, char **argv) ...
    (comp.graphics.api.opengl)
  • Accessing base class method using derived class object
    ... using namespace std; ... void display() ... int main ...
    (microsoft.public.dotnet.framework.clr)
  • Accessing base class method using derived class object
    ... using namespace std; ... void display() ... int main ...
    (microsoft.public.dotnet.framework.clr)