First off, I'm having trouble with c++ in a function I intend to use in a game and it won't compile on linux, so I wasn't really sure where to post this. I put together a little console demo of my pathfinder, only it gets these errors:
/tmp/ccn7Uc0Z.o(.text+0x16f): In function `main':
: undefined reference to `map_t::~map_t [in-charge]()'
/tmp/ccn7Uc0Z.o(.text+0x195): In function `main':
: undefined reference to `map_t::~map_t [in-charge]()'
/tmp/ccn7Uc0Z.o(.text+0x266): In function `printpath(map_t&, path_t&)':
: undefined reference to `map_t::get(int, int)'
/tmp/ccn7Uc0Z.o(.text+0x509): In function `findpath(map_t&, path_t)':
: undefined reference to `map_t::get(int, int)'
collect2: ld returned 1 exit status
I can't even begin to decipher this. Does it mean that my #includes aren't set up right or I need to redefine some functions in the map_t class or what?
I'm using g++ on redhat 9, here's the code it has a problem with:
Code:
int main() {
path_t path;
map_t map("default.map");
cout << "STARTING!\n";
path = findpath(map,path);
cout << "DONE!\n";
printpath(map,path);
return 0;
}
void printpath(map_t& map,path_t& path) {
char **disp = new char*[map.w];
int i, j, k;
for (i = 0; i < map.w; ++i)
disp[i] = new char[map.h];
for (i = 0; i < map.w; ++i)
for (j = 0; j < map.h; ++j) {
disp[i][j] = map.get(i,j);
for (k = 0; k < path.nummove; ++k)
if (path.getmove(k)->x == i &&
path.getmove(k)->y == j)
disp[i][j] = '*';
}
disp[map.destx][map.desty] = 'X';
for (i = 0; i < map.w; ++i) {
for (j = 0; j < map.h; ++j)
cout << disp[i][j];
cout << endl;
delete [] disp[i];
}
delete [] disp;
}
path_t findpath(map_t& map, path_t path) {
if (path.lastmove()->x == map.destx &&
path.lastmove()->y == map.desty) {
return path;
}
move_t testmove[4];
bool valid[4];
int numvalid = 0, min = INT_MAX, minpos = -1;
int i = 0, j = 0, dx, dy;
for (dx = -1; dx <= 1; dx += 2)
for (dy = -1; dy <= 1; dy += 2) {
testmove[i].x = path.lastmove()->x + dx;
testmove[i].y = path.lastmove()->y + dy;
if (testmove[i].x >= 0 && testmove[i].x < map.w &&
testmove[i].y >= 0 && testmove[i].y < map.h &&
map.get(testmove[i].x,testmove[i].y == '0')) {
valid[i] = true;
++numvalid;
}
++i;
}
path_t *testpath = new path_t[numvalid];
for (i = 0; i < 4; ++i)
if (valid[i]) {
testpath[j].add(path);
testpath[j].add(testmove[i]);
testpath[j] = findpath(map,testpath[j]);
if (testpath[j].nummove < min) {
min = testpath[j].nummove;
minpos = i;
}
++j;
}
delete [] testpath;
if (minpos == -1) {
cout << "NO PATH FOUND!\n";
path_t temp;
return temp;
}
path.add(testmove[minpos]);
return findpath(map,path);
}