gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Function mis-match

#172121 - zelbo - Sat Jan 16, 2010 8:08 pm

i'm getting the following error when i try to compile my latest monstrosity:
Code:
c:/devkitPro/projects/Quest_yarlds0.0.0f/source/gameMain.cpp: In function 'int m
ain()':
c:/devkitPro/projects/Quest_yarlds0.0.0f/source/gameMain.cpp:799: error: no matc
hing function for call to 'Monster::checkSpace(int&, int (*)[23][32], int (*)[23
][32])'
c:/devkitPro/projects/Quest_yarlds0.0.0f/include/monster.h:113: note: candidates
 are: int Monster::checkSpace(int, int*, int*)
make[1]: *** [gameMain.o] Error 1
rm txtSprites.s avatar.s bgEGA8x8.s
make: *** [build] Error 2

listCreatures and listTerrain are where i keep track of what is where for exactly this kind of check.
How do i make this work? Can you recommend a better way to do this?
I'm thinking i can just check the actual map, but i don't really have my actual map in place yet.
currently working on switching from iprintf-ing the game screen to sprites on a background.
hit this bump while pulling the monster class into it's own files, using the patater orange spaceship code as a framework.

Call in gameMain.cpp (yeah, i know. switch statements. i have some re-factoring to do.):
Code:
switch (player->checkSpace(direction, &listCreatures, &listTerrain))

Function in monster.cpp:
Code:
   int Monster::checkSpace(int direction, int * plistCreatures, int * plistTerrain)
   {
   // potentials
   int potX;
   int potY;
   
   // 0=none 1=Creature 2=Wall 3=Water 4=Door
   int obstacle;
   /*
      1) check creature array for monsters
         fight?
      2) check terrain array for walls/water/door
         bump head/ swim? / open?
   */
      switch (direction)
      { // first figure out what square we're looking at
         case (D_UP):
            potX = this->x;
            potY = this->y - 1;
            break;
         case (D_RIGHT):
            //this->x++;
            potX = this->x + 1;
            potY = this->y;
            break;
         case (D_DOWN):
            //this->y++;
            potX = this->x;
            potY = this->y + 1;
            break;
         case (D_LEFT):
            //this->x--;
            potX = this->x - 1;
            potY = this->y;
            break;
         default:
            ; // idle/rest?
            break;
      }
      
      if (plistCreatures[potY][potX] > 0)
      {
         obstacle = 1;
      }
      else if (plistTerrain[potY][potX] == 35)
      {
         obstacle = 2;
      }
      else if (plistTerrain[potY][potX] == 126)
      {
         obstacle = 3;
      }
      else if (plistTerrain[potY][potX] == 43)
      {
         obstacle = 4;
      }
      else
      {
         obstacle = 0;
      }
      return obstacle;
   }

#172124 - zelbo - Sun Jan 17, 2010 1:08 am

At least i've stopped getting the error now, but i still don't think this is how i should be doing it.

Call:
Code:
switch (player->checkSpace(direction, listCreatures, listTerrain))

Function prototype:
Code:
int Monster::checkSpace(int direction, int plistCreatures[23][32], int plistTerrain[23][32]);


Now i'm having all sorts of fun trying to get my sprites to show up. Don't know if it's a priority issue or something else i'm screwing up. I'll keep working on it, but i'll probably be coming back here for help before too long.

#172125 - gauauu - Sun Jan 17, 2010 2:59 am

Edit: Kusma's right, I'm a moron. Teaches me not to post when my brain isn't working fully.

Your second post also correctly solves the problem a different way...you indicate that you are expecting a 2d array of ints in the function signature, and that's what you pass in.


Last edited by gauauu on Sun Jan 17, 2010 4:23 pm; edited 1 time in total

#172126 - kusma - Sun Jan 17, 2010 3:53 am

gauauu wrote:
Ok, my brain is working a bit slow right now, so take this with a grain of salt:

If listCreatures is a 2-dimensional int array, then you can also think of it as a pointer to a pointer to an int (since an array can be thought of as a pointer to an int, and this is an array of arrays).

This is completely wrong. A pointer to a pointer is two levels of indirections, but a two-dimensional array is contiguous in memory and thus only one.

#172127 - zelbo - Sun Jan 17, 2010 5:20 am

so would i be better off with something like:
Code:
int Monster::checkSpace(int direction, int * plistCreatures, int * plistTerrain)

and
Code:
switch (player->checkSpace(direction, listCreatures, listTerrain))

so i'm only passing pointers instead of the entire array?