Message-ID: <36BE24E8.3AD4D31@bignet.net> From: John Soares X-Mailer: Mozilla 4.5 [en] (Win95; I) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Instantiation/templating syntax errors Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 196 NNTP-Posting-Host: 206.67.96.202 X-Trace: news9.ispnews.com 918420234 206.67.96.202 (Sun, 07 Feb 1999 15:43:54 EDT) NNTP-Posting-Date: Sun, 07 Feb 1999 15:43:54 EDT Organization: ISPNews http://ispnews.com Date: Sun, 07 Feb 1999 15:42:32 -0800 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com I am getting some strange syntax errors involving instantiation and templates. Here are two structures that reside in the main driver file: struct employee //the employee stuff { keyType nbr; //nine chars only char last_name[worker_last]; char first_name[worker_first]; int trained; //'0' or '1' only int skill[skills]; //room for 5 skills--1 to 50 }; struct project //the project stuff { char nbr[proj_nbr]; //3 chars only char name[skills]; char room[proj_room]; int skill[skills]; //room for 5 project skills int nbr_unskilled_wkrs_needed; //how many workers needed }; int main() { treeNode employee_tree; //employee_info; treeNode project_tree; //project info employee emp; //instance employee_info_entry(emp); //enter info on employee bool success = false; employee_tree.SearchTreeInsert(emp, success); //insert info into tree //other stuff return 0; } In my implementation file, there are two troubled methods. They have worked fine before without templating thrown in. See the syntax errors below. template void treeNode::SearchTreeRetrieve(keyType SearchKey, S& TreeItem, bool& Success) { RetrieveItem(Root, SearchKey, TreeItem, Success); } template void treeNode::RetrieveItem(ptrType TreePtr, keyType SearchKey, S& TreeItem, bool& Success) { cout << endl << "search key is: " << SearchKey << endl; if (TreePtr == NULL) { Success = false; //empty tree cout << endl << "tree must be empty"; } else if (SearchKey == TreePtr->Item.nbr) { //item at root of some subtree cout << endl << "got into retrieval from root"; TreeItem = TreePtr->Item; Success = true; } else if (SearchKey < TreePtr->Item.nbr) { //search the left subtree cout << endl << "into search left subtree"; RetrieveItem(TreePtr->LChildPtr, SearchKey, TreeItem, Success); } else if (SearchKey > TreePtr->Item.nbr) { //search the right subtree cout << endl << "into search right subtree"; RetrieveItem(TreePtr->RChildPtr, SearchKey, TreeItem, Success); } } template void treeNode::SearchTreeDelete(keyType SearchKey, bool& Success) { DeleteItem(Root, SearchKey, Success); } template void treeNode::DeleteItem(ptrType& TreePtr, keyType SearchKey, bool& Success) { //calls DeleteRootItem if (TreePtr == NULL) { cout << "is TreePtr NULL?"; Success = false; //empty } else if (SearchKey == TreePtr->Item.nbr) { //item at the root of some subtree DeleteRootItem(TreePtr); //delete the item Success = true; } else if (SearchKey < TreePtr->Item.nbr) //search left subtree DeleteItem(TreePtr->LChildPtr, SearchKey, Success); else if (SearchKey < TreePtr->Item.nbr) //search right subtree DeleteItem(TreePtr->RChildPtr, SearchKey, Success); } ***ptrType is defined in .h file as: typedef treeNode* ptrType; //pointer to the tree..hmm, this is also the name //of my class, I just noticed. Problem? ***keyType is defined in my .h file as: typedef unsigned long keyType; When I run using egcs using the usual g__~1 filename.cpp -W -o filename.exe, I get the following error messages: 121-P4~1.cpp: In method `void treeNode::DeleteItem(class treeNode *&, long unsigned int, bool &)': 121-P4~1.cpp:63: instantiated from `treeNode::SearchTreeDelete (long unsigned int, bool &)' 121p4drv.cpp:372: instantiated from here 121-P4~1.cpp:324: ANSI C++ forbids comparison between pointer and integer 121-P4~1.cpp:63: instantiated from `treeNode::SearchTreeDelete (long unsigned int, bool &)' 121p4drv.cpp:372: instantiated from here 121-P4~1.cpp:332: warning: ANSI C++ forbids comparison between pointer and integer 121-P4~1.cpp:335: warning: ANSI C++ forbids comparison between pointer and integer 121-P4~1.cpp: In method `void treeNode::RetrieveItem (class treeNode *, long unsigned int, struct project &, bool &)': 121-P4~1.cpp:69: instantiated from `treeNode::SearchTreeRetrieve (long unsigned int, project &, bool &)' 121p4drv.cpp:372: instantiated from here 121-P4~1.cpp:353: ANSI C++ forbids comparison between pointer and integer 121-P4~1.cpp:362: warning: ANSI C++ forbids comparison between pointer and integer 121-P4~1.cpp:370: warning: ANSI C++ forbids comparison between pointer and integer ***I think I am getting the warning messages about comparison between pointers and integers because I am comparing a long integer against a pointer to a structure member. What user must do to delete a node is to type in the employee number(which is datatype long). Then the program would look through the tree to find a matching employee number and delete it. So the user ostensibly would type in a long integer. Am I not comparing this with keyType(long) nbr, residing in the employee structure? Do I need to point to this structure member? ***Also, it looks like I am double instantiating just two functions, the delete and retrieve functions. I'm really lost here, can someone explain why I accessed the project structure, when I did not mention it at all it my short main() test function? Thanks for any hints. John