I have 5 files that I'm trying to link together; 2 header files with class declarations, 2 cpp files with Class definitions, and 1 file with the main method
Header File 1: city.h
#ifndef CITY_H
#define CITY_H
class City
{
// Class header code
}
#endif
Definition File 1: city.cpp
#include "City.h
#include <iostream>
#include <string.h>
#ifndef CITY_H
#define CITY_H
//Class definition code
#endif
This is where I'm getting an error when compiling
Header File 2: hash.h
#include "City.h
#include <iostream>
#include <string.h>
#ifndef CITY_H
#define CITY_H
//Class definition code
#endif
Definition File 2: hash.h
#include "Hash.h"
#include <iostream>
#include <string.h>
#ifndef HASH_H
#define HASH_H
//Class definition
#endif
.cpp File with Main Method
#include "Hash.cpp"
#include "City.cpp"
using namespace std;
int main()
{
int size;
Hash* table = new Hash(size);
return 0;
}
When I compile with g++ I get the following error:
/tmp/ccXGXFpg.o: In function 'main':
Project1.cpp:(.text+0x28): undefined reference to 'Hash::Hash(int)'
collect2: error: 1d returned 1 exit status
I'm really not sure what's wrong. The constructor for Hash is overloaded so there is a Hash::Hash() and Hash::Hash(int) definition. I've been trying to figure it out but I'm beat. Any help is much appreciated, thank you!