Public Group

I have three error using allegro and C++

This topic is 3968 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts


#include <allegro.h>
#include <cstdlib>
#include <time.h>
#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 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;

}

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

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

{
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)
{
}

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 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).

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 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"

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

You want delete control not delete *control

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5
khawk
11

• 10
• 9
• 9
• 11
• 11
• Forum Statistics

• Total Topics
633680
• Total Posts
3013302
×