Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Beginner Needing Help

Credits go to Indeterminatus for helping out!
This thread is locked; no one can reply to it. rss feed Print
Beginner Needing Help
DrgnAK
Member #8,687
May 2007

Hi, I'm rather new to C++, and I can't figure out why this can't compile:

1#include <allegro.h>
2#include <iostream>
3 
4class paddle {
5 protected:
6 fix x,y;
7 public:
8 paddle(fix _x, fix _y);
9 ~paddle();
10 void control();
11}
12 
13paddle::paddle(fix _x, fix _y) {
14 x = _x; y = _y;
15}
16 
17paddle::~paddle() {}
18 
19void paddle::control() {
20 if (key[KEY_UP]) --y;
21 if (key[KEY_DOWN]) ++y;
22}
23 
24int main(int argc, char *argv[])
25{
26 allegro_init();
27 install_keyboard();
28 set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,480,0,0);
29 paddle myPlayer(5,240);
30 
31 return 0;
32}
33END_OF_MAIN();

I get six compile errors in Code::Blocks. They are:

Quote:

error: new types may not be defined in a return type
note: (perhaps a semicolon is missing after the definition of `paddle')
error: return type specification for constructor invalid
error: no matching function for call to `paddle::paddle(int, int)'
note: candidates are: paddle::paddle(const paddle&)
paddle::paddle(fix, fix)

Could someone help, please? ??? I've spent a while trying to figure this out and I don't know what's wrong. Even if I turn fix to int, I still get the first three errors.

Indeterminatus
Member #737
November 2000
avatar

Quote:

note: (perhaps a semicolon is missing after the definition of `paddle')

...and that's exactly what went wrong here :)

class paddle {
    protected:
        fix x,y;
    public:
        paddle(fix _x, fix _y);
        ~paddle();
        void control();
}; // <-- mind the semicolon

paddle::paddle(fix _x, fix _y) {
    x = _x; y = _y;
}

_______________________________
Indeterminatus. [Atomic Butcher]
si tacuisses, philosophus mansisses

DrgnAK
Member #8,687
May 2007

Oh... heh. Didn't realise that I needed a semicolon there. The error seemed odd to me and I didn't know what to do with it :) Thanks! I'm truly grateful for your help.

Go to: