Sign in to follow this  
yurian

I have three error using allegro and C++

Recommended Posts


#include <allegro.h>
#include <cstdlib>
#include <time.h>
#define edeadplace 250
#define pdeadplace 70
#define p 100
#define e 540
#define y 240
#define center 320

bool gamenotquit = true;

class allthings
{
      int level;
      int attackcount;
      int strikecount;
      int attacktime;
      int striketime;
      bool haswon;
      bool failure;
      
      BITMAP*player,*playera,*playerd,*zyars,*zyarsa,*zyarsd,*vandy,*vandya,*vandyd,*mitsu,*mitsua,*mitsud,*ryoku,*ryokua,*ryokud,*drksp,*drkspa,*drkspd;
      BITMAP*champion,*valley,*redraw,*start,*failx;
      SAMPLE*wavplayera,*wavzyarsa,*wavvandya,*wavmitsua,*wavryokua,*wavdrkspa,*wavwind,*attacksignal;
      public:
             allthings();
             ~allthings();
             void declaration();
             void faillevel();
             void playerwin();
             void enemywin();
             void attacktie();
             void enemyattack();
             void playerattack();
             void nextlevel();
             void menu();
             void resetlevel();
             void warscreen();
             void attackplus();
             void strikeplus();
};

allthings::allthings()
{
                      install_int_ex(attackplus,SECS_TO_TIMER(1));
                      install_int_ex(strikeplus,MSEC_TO_TIMER(100));
                      LOCK_VARIABLE(attackcount);
                      LOCK_FUNCTION(attackplus);
                      LOCK_VARIABLE(strikecount);
                      LOCK_FUNCTION(strikeplus);
    
                      level = 1;
                      attackcount = 0;
                      strikecount = 0;
                      attacktime = 0;
                      striketime = 0;
                      haswon = false;
                      failure = false;
      
                      player = load_bitmap("player.bmp",NULL);
                      playera = load_bitmap("playera.bmp",NULL);
                      playerd = load_bitmap("playerd.bmp",NULL);
                      
                      zyars = load_bitmap("zyars.bmp",NULL);
                      zyarsa = load_bitmap("zyarsa.bmp",NULL);
                      zyarsd = load_bitmap("zyarsd.bmp",NULL);
                      
                      vandy = load_bitmap("vandy.bmp",NULL);
                      vandya = load_bitmap("vandya.bmp",NULL);
                      vandyd = load_bitmap("vandya.bmp",NULL);
                      
                      mitsu = load_bitmap("mitsu.bmp",NULL);
                      mitsua = load_bitmap("mitsua.bmp",NULL);
                      mitsud = load_bitmap("mitsud.bmp",NULL);
                      
                      ryoku = load_bitmap("ryoku.bmp",NULL);
                      ryokua = load_bitmap("ryokua.bmp",NULL);
                      ryokud = load_bitmap("ryokud.bmp",NULL);
                      
                      drksp = load_bitmap("drksp.bmp",NULL);
                      drkspa = load_bitmap("drkspa.bmp",NULL);
                      drkspd = load_bitmap("drkspd.bmp",NULL);
                      
                      champion = load_bitmap("champion.bmp",NULL);
                      valley = load_bitmap("valley.bmp",NULL);
                      redraw = load_bitmap("redraw.bmp",NULL);
                      start = load_bitmap("start.bmp",NULL);
                      start = load_bitmap("failx.bmp",NULL);
}

void allthings::attackplus()
{attackcount++;}END_OF_FUNCTION(attackplus);
void allthings::strikeplus()
{strikecount++;}END_OF_FUNCTION(strikeplus);

... //<-- a hundred lines of random stuff

void allthings::menu()
{
     draw_sprite(screen,start,0,0);
     if(key[KEY_ENTER])
     {
                       warscreen();
     }
     else if(key[KEY_ESC])
     {
                         gamenotquit = true;
     }
}


int main()
{
    allegro_init();
    
    install_keyboard();
    
    install_timer();
    
    install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,NULL);
    
    set_color_depth(16);
    set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,480,0,0);
    
    srand(time(NULL));
    
    allthings*control = new allthings;
    
    while(gamenotquit == true)
    {
           menu();
    }
    
    
     clear_keybuf();
     delete *control;
     return 0;
}END_OF_MAIN();



I have three error, "argument of type void(allthings::)()does not match void(*)()" For the two install_int_ex lines in allthings constructor "menu undeclared, first use this function" "type class allthings argument given to delete, expected pointer" I can understand none of these! :( I'm so close, I can touch the goal... but then not with my feet, which are the only parts that count in a race... So sorry if I do not include enough code or do something wrong, please ask me =)

Share this post


Link to post
Share on other sites

allthings*control = new allthings;

while(gamenotquit == true)
{
menu();
}



Your menu is undeclared because it was defined within a class (allthings), so it must be accessed through an object of type allthings.

What you've done - put all things in a class - is not the purpose of classes. Classes should be used to encapsulate things that are relevant to each other. For instance, you would have a Unit class that handles everything relating to a unit (including both the user's unit i.e. character, as well as enemy units). By putting all the relevant data into a class, you can then create a ton of objects of that class (you could create 11 Units, 1 Unit for your user to control and 10 Unit's to serve as the users enemies).

What I'm getting to is that you should probably take everything out of that class and create several smaller classes that contain only relevant things. In this particular case, menu() wouldn't really belong in the Unit class since the menu has nothing to do with a Unit.

So, you would want to make menu() a global function.

But, if you don't want to do all of what I just said, then you've already created an object of type allthings in your code, but when you call menu() you have to access it through your object of type allthings (since menu() is contained in the allthings class).

So you would do: control->menu()

As for "type class allthings argument given to delete, expected pointer," that error comes from this line (obviously) delete *control;.

The problem is that you've included a *, which will de-reference the object that your pointer points to. In other words, *control is of type allthings (since control points to an object of type allthings), but delete only wants a pointer, not an object, so you don't want to include that *.

Change your code to: delete control

Share this post


Link to post
Share on other sites
Shakedown is correct; there's really no point in one giant class that does everything. It's no better than just having a bunch of free functions, really.

Quote:

"argument of type void(allthings::)()does not match void(*)()"
For the two install_int_ex lines in allthings constructor


install_int_ex expects a pointer to a function which takes no parameters and returns nothing (ie, a void (*)()). You've instead provided a pointer to a member function which takes no parameters and returns nothing (ie, a void(allthings::*)()). Make attackplus and strikeplus static, or remove them from the allthings class.

Quote:

"menu undeclared, first use this function"

You want control->menu() not menu().

Quote:

"type class allthings argument given to delete, expected pointer"

You want delete control not delete *control

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this