delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/02/07/16:12:57

Message-ID: <36BE24E8.3AD4D31@bignet.net>
From: John Soares <moose AT bignet DOT net>
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
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> employee_tree;           //employee_info;
 treeNode<project> 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 <class S>
void treeNode<S>::SearchTreeRetrieve(keyType SearchKey, S& TreeItem,
bool& Success)
{
 RetrieveItem(Root, SearchKey, TreeItem, Success);
}

template <class S>
void treeNode<S>::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 <class S>
void treeNode<S>::SearchTreeDelete(keyType SearchKey, bool& Success)
{
 DeleteItem(Root, SearchKey, Success);
}


template <class S>
void treeNode<S>::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<project>::DeleteItem<project>(class treeNode<project> *&,
long unsigned int, bool &)':
121-P4~1.cpp:63:   instantiated from
`treeNode<project>::SearchTreeDelete<project>
(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<project>::SearchTreeDelete<project>
(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<project>::RetrieveItem<project>
(class treeNode<project> *, long unsigned int, struct project &, bool
&)':
121-P4~1.cpp:69:   instantiated from
`treeNode<project>::SearchTreeRetrieve<project>
(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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019