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 | |
4 | class paddle { |
5 | protected: |
6 | fix x,y; |
7 | public: |
8 | paddle(fix _x, fix _y); |
9 | ~paddle(); |
10 | void control(); |
11 | } |
12 | |
13 | paddle::paddle(fix _x, fix _y) { |
14 | x = _x; y = _y; |
15 | } |
16 | |
17 | paddle::~paddle() {} |
18 | |
19 | void paddle::control() { |
20 | if (key[KEY_UP]) --y; |
21 | if (key[KEY_DOWN]) ++y; |
22 | } |
23 | |
24 | int 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 | } |
33 | END_OF_MAIN(); |
I get six compile errors in Code::Blocks. They are:
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.
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; }
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.