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.

Beginners > Help with error during compiling

#149932 - Cave Johnson - Sun Jan 27, 2008 4:38 pm

I've been working on this same simple code of a background and a fish sprite that i could control, for a week or two now, and im in the compiling stage. I have narrowed it down to 3 errors in the main.cpp, but i cannot figure out for the life of me how to fix it. Could anyone help me? The errors i get are:

c:/Taylor/dsprojects/source/main.cpp: In function 'int main()':
c:/Taylor/dsprojects/source/main.cpp:187: error: expected type-specifier before 'fish'
c:/Taylor/dsprojects/source/main.cpp:187: error: cannot convert 'int*' to 'fish*' in initialization
c:/Taylor/dsprojects/source/main.cpp:187: error: expected ',' or ';' before 'fish'

Here is the int main() and highlighted the problem area:

int main() {
powerON(POWER_ALL_2D);

irqInit();
irqSet (IRQ_VBLANK, 0);

lcdMainOnBottom();
initVideo();
initBackgrounds();

dopefishInfo spriteInfo[SPRITE_COUNT];
tOAM *oam = new tOAM();
initOAM(oam);
initSprites(oam, spriteInfo);
//colors_slot1 is the background picture
displaycolors_slot1();
//dopefish is the fish sprite im using
static const int DOPEFISH_OAM_ID = 0;
//fish is the class
SpriteEntry * fishEntry = &oam->spriteBuffer[DOPEFISH_OAM_ID];
SpriteRotation * fishRotation = &oam->matrixBuffer[DOPEFISH_OAM_ID];
fish * fish = new fish(&spriteInfo[DOPEFISH_OAM_ID]); //<-Heres the error line!!!!!!!!!!!!!!!!

for (int i = 0; i < 10; i++) {
fish->accelerate();
}

for (;;) {

handleInput(fish);
fish->movefish();

MathVector2D<float> position = fish->getPosition();
fishEntry->posX = (int)position.x;
fishEntry->posY = (int)position.y;
rotateSprite(fishRotation, fish->getAngleDeg512());

swiWaitForVBlank();
updateOAM(oam);
}


return 0;
}

If you need to see any more of my files (sprite.cpp, fish.cpp, fish.h, sprite.h, or more of main.cpp) id be glad to post them, because like i said, i dont know what you need to see so that you can help me. Thanks for the help.

#149934 - nipil - Sun Jan 27, 2008 5:09 pm

Cave Johnson wrote:
fish * fish = new fish(...);

I guess that "fish" is a class ? or at least a valid type. The compiler cannot declare a variable with the exact same name as a type. A rule of thumb with non-standard types (class, structs, etc) is to have the first letter be uppercase. So my advice would be to try something like : Fish * myfish ... and rename all the "fish" afterwards to "myfish". In case you're not clear about data types and variable declaration, i would advice you to read some basic tutorials about C/C++ programming. Without a good insight on how types and variables work, you'll hit your head into walls, again, and again.

#149943 - Cave Johnson - Sun Jan 27, 2008 8:10 pm

Thanks for the help nipil, that was my problem. Except when it compiled i got some MAJOR graphical glitches that ill need to iron out. Thanks again.