Hi! I am learning to code and allegro and am starting to do my first legitimate
game, but I need some help. I am creating a map class and in my constructor I come up with these two errors:
Map.cpp: Error: invalid use of incomplete type 'ALLEGRO_BITMAP{aka struct ALLEGRO_BITMAP}
\Allegrolib\...99 error: forward declaration of 'ALLEGRO_BITMAP{aka struct ALLEGRO_BITMAP}
#ifndef MAP_H
#define MAP_H
//Allegro Files
#include <allegro5\allegro.h>//Holy allegro header
#include <allegro5\allegro_acodec.h>//Our acodec file
#include <allegro5\allegro_audio.h>//Our audio file
#include <allegro5\allegro_image.h>//Our Image file
#include <allegro5\allegro_primitives.h>//Our primitive header file
//Classes
#include "Map.h"
#include "Road.h"
#include "Player.h"
usingnamespace std;
class Map
{
public:
Map(int sizeX, int sizeY, int numberOfBoundaries, Road boundaries[], ALLEGRO_BITMAP* map);
~Map();
bool isInRoad(int xPos,int yPos);
protected:
private:
//The size of the map in X and Y format.
int mapSizeX;
int mapSizeY;
//A virtual "road". This will be the set of places the player can travel on. Each
//"Road" is its own set of coordinates the player can travel on.
Road roads[1];
//Obviously, who's playing. Later on this may be an array for multiplayer.
Player player;
//The acutal map picture. Other cars will be added on via the road class.
ALLEGRO_BITMAP *mapGraphic;
};
#endif // MAP_H
//Allegro Files
#include <allegro5\allegro.h>//Holy allegro header
#include <allegro5\allegro_acodec.h>//Our acodec file
#include <allegro5\allegro_audio.h>//Our audio file
#include <allegro5\allegro_image.h>//Our Image file
#include <allegro5\allegro_primitives.h>//Our primitive header file
//Classes
#include "Map.h"
#include "Road.h"
#include "Player.h"
usingnamespace std;
//Main map constructor
//ERROR HERE
Map::Map(int sizeX, int sizeY, int numberOfBoundaries, Road boundaries[], ALLEGRO_BITMAP* map)
{
for(int i=0;i<sizeof(boundaries)/sizeof(boundaries[0]);i++){
Road* bPointer=roads;
map->roads[i]=boundaries[i];
bPointer = new Road[1];
}
}
//Havent built this yhet
Map::~Map()
{
//dtor
}
bool Map::isInRoad(int xPos, int yPos){
//Checks if the player is on a road or not.
int i=0;
while(true){
//Sees if the player is in a certain road.
if(roads[i].isInBounds(player)){
returntrue;
}
//Integrates the counter
i++;
//If weve gone through all possible roads, exit the program.
if(i==sizeof(roads)/sizeof(roads[0])){
returnfalse;
}
}
}
//Main map constructor
Map::Map(int sizeX, int sizeY, int numberOfBoundaries, Road boundaries[], ALLEGRO_BITMAP* map)
{
//ERROR - Next line
//you cannot get the size of an array from
//a function parameter like this
for(int i=0;i<sizeof(boundaries)/sizeof(boundaries[0]);i++)
{
Road* bPointer=roads;//see comment below concerning bPointer
//Next line
// map is a pointer to an ALLEGRO_BITMAP
//I'm sure it has nothing to do with roads - plus
//it is an opaque type
//so map->roads is incorrect use
map->roads[i]=boundaries[i]; //
bPointer = new Road[1]; //and what is going on with this bPointer?
}
}