Неопределенная ссылка на 'HashTable :: HashTable ()' - PullRequest
0 голосов
/ 27 февраля 2020

Я работаю над тестовой программой для лаборатории и получаю сообщение об ошибке

[jereminp@bondi hw3]$ make insert_test
g++  -O3 -g -o insert_test.o -c insert_test.cc
g++ -O3 -g -o insert_test insert_test.o
insert_test.o: In function `main':
/users/ugrad/2018/fall/jereminp/114/hw3/hw3/insert_test.cc:17: undefined reference to `HashTable::HashTable()'
/users/ugrad/2018/fall/jereminp/114/hw3/hw3/insert_test.cc:24: undefined reference to `HashTable::insert(int)'
/users/ugrad/2018/fall/jereminp/114/hw3/hw3/insert_test.cc:32: undefined reference to `HashTable::insert(int)'
collect2: ld returned 1 exit status
make: *** [insert_test] Error 1

Я почти уверен, что у меня есть логика c, но я не могу пройти через это ошибка, и я чувствую, что упускаю что-то простое. Вот части кода, о которых идет речь.

Makefile

CC = g++
CFLAGS =
COPTFLAGS = -O3 -g

insert_test: insert_test.o
    $(CC) $(COPTFLAGS) -o $@ $^

insert_test. cc

#include "HashTable.h"
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <math.h>

using namespace std;
class HashTable;

int main(int argc, char* argv[])
{
  //checks .5 and .9 1x
  int numRuns = 0;
  int numProbes = 0;
  int a=0;
  HashTable h;

HashTable.hh

#ifndef HASHTABLE_H
#define HASHTABLE_H


class HashTable
{
  public:
  HashTable();
  /* implement copy constructor, assignment, destructor if needed */
  int hashfnc(int key);
  int insert (int value); 
  /* insert the input value and return the number of probes
   * return -1 if the table is full and insert fails */

  bool find (int value, int& nProbes);  
  /* Search for the input value in table
   * Return true if the search is successful, otherwise false
   * Save # probes in 'nProbes' */

  // getters
  int capacity() { return nSlot; }
  int size() { return nElem; }
  double load_factor() { return load; }
  int getSearchProbes() { return probesSearch; }

  private:
  /* declare your data */
  double load;     // track the load factor of table
  int    nSlot;    // # slots i.e. max # elements can hold 
  int    nElem;    // current # elements in table
  int    arr[];
  int    probesSearch;
};

#endif

HashTable. cc

#include "HashTable.h"
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

class HashTable
{
  public:


  HashTable()
  {
    load = 0;
    nSlot = 300;//nSlot is changable in order to optimize
    nElem = 0;
    arr = new int[nSlot];
    probesSearch=0;
    for(int i = 0;i<nSlot;i++)
    {
      arr[i] = NULL;
    }
  }

Некоторые из вещей, которые я пробовал, - это добавлять все, что я мог придумать, меняя последнюю строку, показанную в insert_test. cc на «HashTable h = new HashTable ();» (где я получил другую ошибку), добавив пространство имен std в заголовок. Я чувствую, что это должно быть быстрое решение, но в то же время я не могу найти решение нигде. Пожалуйста, отправьте помощь

...