- 论坛徽章:
- 0
|
虽然是warning,还是不爽啊
出错的程序:
- class SymbolTable
- {
-
- public:
- SymbolTable();
- SymbolTable(const char[]); // name of file
- void File(const char[]); // connect file
- ~SymbolTable();
- void Make();
- void Print();
- private:
- Program Prog;
- BinaryTree<WordPtr>; ST;
- };
复制代码
- void SymbolTable::Make()
- {
- // Using the function GetNextToken from the Program class
- // set up a loop that gets the next token and, if it is not
- // already in the binary tree ST, inserts it.
- // Use Locate to test if the item already exists.
- int line=0;
- char* word;
- WordPtr wd1, wd2;
-
- //
- Program rserrved;
- rserrved.Open("ReservedWords.txt");
- while(1)
- {
- word=new char[30];
- if (!rserrved.GetNextToken(word, line)){
- delete[] word;
- break;
- }
- wd1 = new ReservedWord(word);
- ST.Insert(wd1);
- word=new char[30];
- }
-
- while(1)
- {
- word=new char[30];
- if (!Prog.GetNextToken(word, line)){
- delete[] word;
- break;
- }
- wd1 = new Identifier(word);
- wd1->;Update(line);
- if (ST.Locate(wd1, wd2))
- {
- delete[] word;
- delete wd1;
- wd2->;Update(line);
- }
- else
- {
- ST.Insert(wd1);
- }
- }
- }
- void SymbolTable::Print()
- {
- // Set up a BinaryTreeIterator attached to the tree ST
- // and loop through the tree, using Print to display
- // what each pointer in the tree points at
- BinaryTreeIterator< WordPtr >; iter(ST);
-
- iter.SetIterator();
- while (iter.More())
- {
- iter.Next()->;Print(cout);
- }
- }
复制代码
这两句有问题,而且都是 "Where: Instantiated from non-template code"
// ST.Insert(wd1);
// if (ST.Locate(wd1, wd2))
相关的代码
- template <class T>;
- class BinaryTree
- {
- friend class BinaryTreeIterator<T>;;
-
- public:
- BinaryTree();
- ~BinaryTree();
- void Insert(const T&);
- bool Locate(const T&, T&);
- bool Delete(const T&, T&);
- struct node;
- typedef node *nodePtr;
- struct node
- {
- T data;
- nodePtr left, right, parent;
- };
- private:
- nodePtr root;
-
- nodePtr FindNode(const T&, nodePtr);
- void InsertNode(const T&, nodePtr&);
- void PostOrderDelete(nodePtr);
- };
复制代码
- template<class T>;
- void BinaryTree<T>;::Insert(const T& data)
- {
- InsertNode(data, root);
- }
- template<class T>;
- bool BinaryTree<T>;::Locate(const T& data, T& founddata)
- {
- nodePtr foundNode = FindNode(data, root);
-
- if (foundNode != 0)
- {
- founddata = foundNode->;data;
- return true;
- }
- else
- return false;
- }
复制代码 |
|