无法调用其他类/方法

时间:2016-04-14 22:16:01

标签: c++

我正在努力(我想我已经正确地完成了??)一个hashTable并且已经一路走到尽头我已经达到了一点速度...... / p>

#include <iostream>
#include <fstream>
#include "hashTable.h"
#include <string>
#include <time.h>
#include <ctime>

using namespace std;

int main(int argc, char* argv[]){

  clock_t start, end;
  double duration;

  start = clock();
    char firstLetter;
    string SSN, firstName, lastName, name; 
    fstream input(argv[1]);
    int count = 0;
    int numInserted = 0;
    int numDeleted = 0;
    int numRetrieved = 0;
    int numTable = 0;

  //Do I need these two? I’ve tried with and without them both/combination of neither
  //and gotten the same issue
  //Node<string>* node = new Node<string>;
  //SLL<string>* SLL = new SLL<string>;

  HashTable<string>* T = new HashTable<string>(10007);


    for(int i = 0; !input.eof(); i++){
        input >> firstLetter >> SSN >> firstName >> lastName;
        name = firstName + " " + lastName;

        switch(firstLetter){
            case 'd':{
                if(T.erase(SSN) == true){
                    numDeleted++;
                    numTable--;
                }
            }
            case 'i':{
                if(T.insert(SSN, name) == true){
                    numInserted++;
                    numTable++;
                }
            }
            case 'r':{
                if(T.find(SSN) == true){
                    numRetrieved++;
                }
            }
        }
    }
    input.close();

  end = clock();
  duration = ( end - start ) / (double) CLOCKS_PER_SEC;
  cout << "The Numer of Valid Insertions: " << numInserted << endl;
  cout << "The Number of Valid Deletions: " << numDeleted << endl;
  cout << "The Number of Valid Retrievals: " << numRetrieved << endl;
  cout << "The Number of Items in Array: " << numTable << endl;
  cout<<"elapsed time: "<< duration <<'\n';
}

上面是我的main.cpp文件,它调用hashTable.h(它调用我的调用我的node.h文件的SLL.h),它具有以下内容:

#include <iostream>
#include "SLL.h"
using  namespace  std;

template <class V>
class HashTable {
    int tableSize; // table size

    SLL<V>* table;

    public:
    // default constructor
    HashTable(){
        …
    }

    // constructor, which use size as the table size
    HashTable(int size){
      …
    }

    // search item in the table     
    // if found, return true; otherwise, return false
    bool find(V item){
      …
    }

    // insert (item1, item2) to the table
    // use item1 as the key
    // if inserted, return true
    // otherwise, return false
    bool insert(V item1, V item2){
      …
    }

    int HashFunc(V item1){
      …
    }

    // delete the pair whose key value is item
    // if deleted, return true
    // otherwise, return false 
    bool erase(V item){
      …
    }

    // return the total number of nodes in the hash table    
    int getSize(){
      …
    }
 };

尝试编译后不用:

Node<string>* node = new Node<string>;
SLL<string>* SLL = new SLL<string>;

我收到T.erase / find / insert的错误,所有人都在说同样的事情,问我是否打算使用&#39; - &gt;&#39;

尝试使用以下命令编译之后:

Node<string>* node = new Node<string>;
SLL<string>* SLL = new SLL<string>;

除了以下内容之外,我得到了相同的3个错误:&#34;在&#39; SLL&#39;之前的预期类型说明符 SLL&LT; string&gt; * SLL = new SLL;

如果我需要添加其他代码,请告诉我,我很乐意这样做。 谢谢你的帮助!

编辑: 所以当我用

编译它时
HashTable<string> T(10007);

我从hashTable.h得到50个错误,所有错误都与我有关/使用 - &gt;在那个文件中。所以我很确定我必须使用指针。然后我继续将上面的内容切换到:

T->insert
T->find
T->erase

之后我从各种各样的事情中得到了50多个错误。在这一点上,我得出的结论是:我的代码不是那么糟糕而且它是一些小问题,现在已经搞砸了所有事情,或者我只是吮吸编程而应该在我落后的时候退休:D那是我在没有SLL和Node的情况下编译的。所以我尝试用这些编译,除了预期的类型说明符之外还得到了相同的错误&#39; SLL&#39;再次:[

0 个答案:

没有答案
相关问题