From: Nathan Cournia Newsgroups: comp.os.msdos.djgpp Subject: Inheritance Problem Date: Fri, 01 May 1998 14:20:11 -0500 Organization: Middle Tennessee State University Lines: 105 Message-ID: <354A206B.586A3F60@frank.mtsu.edu> NNTP-Posting-Host: knuth.mtsu.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk I'm having a problem with inheritance. In my client file I have this line: wordTree Word; I also have this line: Word.Search(Item, Success); The previous line calls a public Search function which in turn calls a private recursive function. The problem is that the public function is calling the private function for the parent class instead of the derived class. Can anybody help. Here are the header file for the two classes and the server file for the derived class. Thanks, Nathan Cournia //FILE: BSTree.h template struct bstNode; template class bstClass { public: bstClass(); //default constructor virtual ~bstClass(); //destructor bstClass(const bstClass& Tree); //copy constructor virtual bool Empty(); //checks of tree is empty virtual void Insert(T& NewItem, bool& Success); //inserts item in tree virtual void PrintInorder(); //prints tree inorder virtual void PrintPostorder(); //prints tree postorder virtual void PrintPreorder(); //prints tree preorder virtual void Search(T Item, bool Success); //searches tree for item protected: void InsertData(bstNode*& P,T& NewItem, bool& Success); //recursive insert function void Inorder(bstNode* P); //inorder recursice function void Postorder(bstNode* P); //postorder recursive function void Preorder(bstNode* P); // preorder recursive function void CopyTree(bstNode* P, bstNode* NewP); //copies tree at P to NewP void SearchTree(bstNode* P, T Item, bool Success); //searches for Item in tree void DestroyTree(bstNode*& P); //recursive function to destroy tree public: bstNode* Root; //root of the tree }; //end of bstClass #include "BSTree.cc" //FILE: WordTree.h #include "Word.h" //for wordClass #include "BSTree.h" class wordTree: public bstClass { protected: void SearchTree(bstNode* P, wordClass Item, bool Success); }; //end of wordTree #include "WordTree.cc" //FILE: WordTree.cc void wordTree::SearchTree(bstNode* P, wordClass Item, bool Success) { if(P==NULL) //check if the list is empty Success=0; else if(Item==P->Data) //item found { Success=1; P->Data.IncFreq(); P->Data.AddLineNumber(); } else if(ItemData) SearchTree(P->LChild, Item, Success); //search left tree else SearchTree(P->RChild, Item, Success); //search right tree } //end of SearchItem()