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++ > Allegro error

#173682 - jam_888 - Fri Apr 23, 2010 9:00 am

Ok, so i made this game anyway i needed a few classes and stuff anyway of course i have functions in it. My pronlem is that i have a void function in my player class and it come's up with this error
error C2062: type 'void' unexpected
.Now i have no idea what this mean's as i declared it in the player header file so it should work and i have used classes before and this is the first time it has happened. I am guessing it has something to do with allegro cause that is the only thing i can think of.
Please help?

edit: here is the code in my player.cpp file
Code:

#include "player.h"

int x = 10;
int y = 10;

player::player():

   void player::move()
   {
      install_keyboard();
   
   while ( !key[KEY_ESC] ){
   
      clear_keybuf();
       
        acquire_screen();
       
        textout_ex(screen, font, "I mixed a few different tutorial's together to make this arrow's = move", 1, 12, 11, -1);
   
        if (key[KEY_UP]) --y;       
        if (key[KEY_DOWN]) ++y;   
        if (key[KEY_RIGHT]) ++x;
        if (key[KEY_LEFT]) --x;

        textout_ex( screen, font, "@", x, y, makecol( 255, 0, 0), makecol( 0, 0, 0) );
      
      release_screen();
       
        rest(20);

   }
}

_________________
i'm in the corner of your eye were you never want to look http://www.mediafire.com/?noymnnmtwmm

#173690 - elhobbs - Fri Apr 23, 2010 5:52 pm

what is your intent with the following bit of code?
Code:
player::player():

#173695 - Drovor - Fri Apr 23, 2010 7:16 pm

Remove the "player::player():" line or finish implementing the constructor.

A colon at the end like that is how you add an initialization list, for example if your player has an "int lives" member you could make the constructor like:
Code:
player::player():lives(3)
{}


Since you end with a colon its expecting to find some member variable but there is an unexpected void form your move method instead.[/code]

#173699 - jam_888 - Sat Apr 24, 2010 3:51 am

Thanks i will try this
_________________
i'm in the corner of your eye were you never want to look http://www.mediafire.com/?noymnnmtwmm

#173700 - jam_888 - Sat Apr 24, 2010 4:19 am

Thank you so much i edited my file and now it works how it should anyway 2 more prblems but mainly this one.
1.I have word's written in the first function but they dont go away in the next function
2.the player leaves a line behind him wereevr he goes
_________________
i'm in the corner of your eye were you never want to look http://www.mediafire.com/?noymnnmtwmm