Invalid use of incomplete type 'ALLEGRO_BITMAP

closed account (oN3AqMoL)
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}

Here is my code:

Map.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#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"

using namespace 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 


Map.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//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"

using namespace 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)){
            return true;
        }
        //Integrates the counter
        i++;
        //If weve gone through all possible roads, exit the program.
        if(i==sizeof(roads)/sizeof(roads[0])){
            return false;
        }
    }
}


Any idea how to fix this?
Last edited on
That whole Map::Map constructor looks suspicious to me.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//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?
    }
}


closed account (oN3AqMoL)
I figured it out. I needed to change map->roads to this->roads. I meant to say Map-> roads as in the class Map-> roads. Thanks anyway!
If you want you can change this->roads to just roads.
Topic archived. No new replies allowed.