Hello! I've been working on a small project in my spare time, and I've run into a problem that I can't seem to figure out. It's a small game that uses a 2-dimensional vector of a "Tile" class. I created another class called "Mapmaker" that will populate the 2-dimensional vector based on input specified in a text file. I'm currently using g++ on cygwin.
The mapmaker header looks like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#ifndef MAPMAKER_H
#define MAPMAKER_H
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cstdlib>
#include "tile.h"
using namespace std;
class Mapmaker
{
public:
Mapmaker();
//Other
vector<vector<Tile> > loadMap(int chnumber, int lvlnumber);
private:
ifstream mapfile;
};
#endif
|
And the relevant part of the cpp file is this:
1 2 3 4 5 6 7 8 9
|
vector<vector<Tile> > nextMap(xSize, vector<Tile>(ySize, Tile()));
for(int x = 0; x < xSize; x++)
{
for(int y = 0; y < ySize; y++)
{
int nextTile = mapfile.get();
nextMap[x][y] = Tile(x,y,0,nextTile);
}
}
|
I compile them both into mapmaker.o with the following command in a Makefile:
1 2 3 4 5
|
CC=g++
CFLAGS=-c
...
mapmaker.o: mapmaker.h mapmaker.cpp
$(CC) mapmaker.h mapmaker.cpp $(CFLAGS)
|
I'm sure the code has some other problems, but I can work those out. However, when I try to use the command to make mapmaker.o, I get the following compiler errors:
mapmaker.o:mapmaker.cpp:(.text+0x2ef): Undefined reference to 'Tile::Tile()'
mapmaker.o:mapmaker.cpp:(.text+0x432): Undefined reference to 'Tile::Tile(int,int,int,int)'
Both of these are specified in the tile.h file, which I've included in mapmaker.h, so mapmaker.cpp should know what the functions are. I've tried including the tile.h and tile.cpp file in the compliation command, but it doesn't fix the problem. I can't think of what I'm missing here.
Thank you for your time!