Problem Compiling Multiple Files

I am trying to compile a .cpp file and a .h file in one project. Whenever I try to build the project in Code::Blocks, I get an error saying "invalid preprocessing directive #include".

Here is main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <allegro.h>
#inlcude "Setup.h"
 int main(){//Rule of thumb, make main() as small as possible

    Startup startup;

    BITMAP *buffer = create_bitmap(640, 480);//For double buffering

    //Main game loop
    while (!key[KEY_ESC]){//Make sure esc is not being hit
        rectfill(buffer, 0 , 0, 640, 480, makecol(255, 0, 0));//Red rectangle

        blit(buffer, screen, 0, 0, 0, 0, 640, 480);//Draw red recangle in buffer

        clear_bitmap(buffer);
    }

    destroy_bitmap(buffer);//Clear RAM!!!


    return 0;
}
END_OF_MAIN();


and Setup.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
#ifndef SETUP_H_INCLUDED
#define SETUP_H_INCLUDED
class Startup{
    Startup();
    ~Startup();
};

Startup::Startup(){
    allegro_init();
    install_timer();
    install_mouse();
    install_keyboard();
    install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, 0);
    set_color_depth(16);

    bool fullscreen = false;

    if(fullscreen){
        set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
    }
    else{
        set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
    }
}

Startup::~Startup(){
    delete fullscreen;
}


#endif // SETUP_H_INCLUDED 


What am I doing wrong?
Or does it say "invalid preprocessing directive #inlcude".
What am I doing wrong?

You're misreading the error message. It says "invalid preprocessing directive #inlcude" because you spelt "include" incorrectly on the second line.
Hopefully this question isn't as stupid, but I'm having trouble with accessing data in one scope from another.

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
#ifndef GAMEOBJECTS_H_INCLUDED
#define GAMEOBJECTS_H_INCLUDED
class GameObject{
    protected:
        int x, y, speed;
};

class Ball: GameObject{
    protected:
        int direction;
};

class Paddle: public GameObject{
    protected:
        int score;
    public:
        void draw_paddle(){
            rectfill(buffer, x, y, x + 20, y + 60);
        }
    }
};

class Player1: public Paddle{
    public:
        void getInput(){
            if(KEY_UP){
                x++;
            }
            else if(KEY_DOWN){
                x--;
            }
    }
};

#endif // GAMEOBJECTS_H_INCLUDED 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <allegro.h>
#include "Setup.h"
#include "GameObjects.h"
 int main(){//Rule of thumb, make main() as small as possible

    Startup startup;

    BITMAP *buffer = create_bitmap(640, 480);//For double buffering

    //Main game loop
    while (!key[KEY_ESC]){//Make sure esc is not being hit

        blit(buffer, screen, 0, 0, 0, 0, 640, 480);//Draw red recangle in buffer

        clear_bitmap(buffer);
    }

    destroy_bitmap(buffer);//Clear RAM!!!


    return 0;
}
END_OF_MAIN();


I know this code has many errors but I want to fix the scope error before I fix others.
I'm having trouble with accessing data in one scope from another.
Yes, that's what scope is for.
¿where is the issue?
line 18 of GameObjects.h
17
18
19
        void draw_paddle(){
            rectfill(buffer, x, y, x + 20, y + 60);
        }
In order to use rectfill, you need to include the proper header.
Now, a Paddle does not know what the hell is 'buffer' so you need to tell it.
void draw_paddle(BITMAP *buffer);

¿Is this the function? http://www.allegro.cc/manual/4/api/drawing-primitives/rectfill
You are one parameter short.
Last edited on
Topic archived. No new replies allowed.