Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Strange compile errors - Can't see anything wrong.

This thread is locked; no one can reply to it. rss feed Print
Strange compile errors - Can't see anything wrong.
Durnus
Member #7,997
November 2006
avatar

I have come code (no duh ::) ) and it is giving me trouble. I am using Dev-C++.

Compiling errors:

expected init-declarator before '*' token
expected `,' or `;' before '*' token
[Build Error] [main.o] Error 1

Also, my Run and Compile and Run icons are diabled.

My code:

1#include <allegro.h>
2#include "particle_array.h"
3 
4 
5BITMAP * interface_bitmap; //It says the error is in THIS LINE.
6 
7bool exit_next_loop = false;
8 
9//Needed to run.
10void init();
11void exit_button();
12 
13//My functions for the interface.
14void draw_interface_to_screen(BITMAP*screen);
15 
16int main() {
17 init();
18
19 int selected_type; //The selected particle
20 int selected_size; //The current size
21
22 particlearray particles;
23 int xmouse = mouse_x;
24 int ymouse = mouse_y;
25
26 while (!exit_next_loop)
27 {
28 xmouse = mouse_x;
29 ymouse = mouse_y;
30 int xmouse = mouse_x;
31 int ymouse = mouse_y;
32 if(mouse_x <= 600 && mouse_b & 1)
33 {
34 particles.new_particle(selected_type, xmouse, ymouse, selected_size);
35 }
36 if(mouse_x <= 600 && mouse_b & 2)
37 {
38 particles.erase_particles(mouse_x, mouse_y, selected_size);
39 }
40
41 blit(particles.draw_to_screen(), screen, 0,0,0,0,600,600);
42 draw_interface_to_screen(screen);
43
44
45 }
46 
47
48 return 0;
49}
50END_OF_MAIN()
51 
52void exit_button()
53{
54 exit_next_loop = true;
55}
56 
57void init() {
58 int depth, res;
59 allegro_init();
60 depth = desktop_color_depth();
61 if (depth == 0) depth = 32;
62 set_color_depth(depth);
63 res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
64 if (res != 0) {
65 allegro_message(allegro_error);
66 exit(-1);
67 }
68
69 set_window_title("Particle Master");
70 
71 install_timer();
72 install_keyboard();
73 install_mouse();
74 /* add other initializations here */
75
76 LOCK_FUNCTION(exit_button);
77 set_close_button_callback(exit_button);
78 
79}

My header file:

1//The Particlearray class.
2// Stores a vector of particles for the user to see.
3 
4 
5#ifndef PARTICLE_ARRAY_H
6#define PARTICLE_ARRAY_H
7 
8 
9#include <vector>
10#include <allegro.h>
11 
12class particle //The particle class. Many of there reside in a particlearray.
13{
14 public:
15
16particle(int type, int x, int y, int particle_size);
17particle();
18 
19int how_close_to(int x, int y); //Returns the distance a bitmap is close to a point.
20bool is_point_in(int x, int y); //Returns if a point is in the particle.
21 
22int return_type(); //Returns the type of the particle.
23 
24void calculate(); //Calculates the "physics" of the particle.
25 
26BITMAP* draw_to(); //Draws the particle on specified bitmap.
27 
28 private:
29
30int x_pos;
31int y_pos;
32 
33int x_vel; // The x and y velocities.
34int y_vel;
35 
36int type; //The particle type.
37 
38}
39 
40 
41 
42//The array of particles.
43class particlearray
44{
45 public:
46 
47void new_particle(int type,volatile int x,volatile int y, int size, bool giantparticle = false); //Makes a new particle at the end of the vector.
48void erase_particles(int x, int y, int size); //Erases the particles.
49BITMAP* draw_to_screen(); //Draws the particles to the specified bitmap.
50 
51 
52 
53 private:
54
55std::vector<particle> particle_vector; //The Particle Vector
56 
57}
58 
59#endif

I have no idea what I did wrong, but this error is keeping me back. :(

kazzmir
Member #1,786
December 2001
avatar

sure, paste particle_array.h. just a thought, try <allegro.h> instead of "allegro.h", but that shouldn't really matter..

TeamTerradactyl
Member #7,733
September 2006
avatar

Durnus, the code looks sound from a 10-second walkthrough, but I would take kazzmir's advice: change "allegro.h" to <allegro.h> since your allegro header file should be found in your compiler's "include" folder and not your local directory.

When compiling, do you have allegro's library declared? Mine (from a DOS box, not Dev-C++) is:

gcc your_program.c -lalleg

Durnus
Member #7,997
November 2006
avatar

I am sure the allegro library is working. When I put in the particle_array.h, that's when the bug happens. I changed it to <allegro.h> anyway.

LennyLen
Member #5,313
December 2004
avatar

Quote:

I am sure the allegro library is working.

Yes, there would have been far more errors had you not linked to the library.

Richard Phipps
Member #1,632
November 2001
avatar

BITMAP * interface_bitmap; //It says the error is in THIS LINE.
If you remove the space between the * and interface_bitmap, does that make any difference?

Durnus
Member #7,997
November 2006
avatar

->Lennylen

Heh, I remember the time I didn't link it. That was the first bug I faced, and that was before I knew about allegro.cc. I had nowhere to turn.

->Richard Phipps

No, I'm afraid that does not help.

More info on the bug:

If I move one of my integer declares to the first line, it says this as the compile error instead:

two or more data types in declaration of `xmouse'
extraneous `int' ignored
conversion from `volatile int' to non-scalar type `particle' requested
[Build Error] [main.o] Error 1

These are the strangest errors I've ever got.

[Random] I just noticed I'm member 7997! Hehe [/Random]

orz
Member #565
August 2000

Add semicolons immediately after the closing curly brace fore each class declaration. Otherwise, it tries to interpret the immediate next stuff as an instance of the class. Not sure quite how you end up with those error messages though : )

Hano Wair
Member #5,243
November 2004
avatar

You didn't put a semicolon ( ; ) after your class declarations.

class Foo { /*. .. */ }     // Wrong
class Bar { /* ... */ };    // Right

[edit] Beaten

Durnus
Member #7,997
November 2006
avatar

How was I that stupid when I made my header file....

I have no clue how that killed my app, but thanks, adding the semicolons worked. ;D

Dang... new problem.

Now when I compile, it won't let me run it. My Run and Compile and Run buttons are disabled. I checked my project folder, and there is no exe being created.

Compiler only says "creating Particle Master.a"

raccoon
Member #7,478
July 2006

i have no idea how Dev-C++ works, but it looks like you are building a library.
maybe you should recheck your project options

LennyLen
Member #5,313
December 2004
avatar

Quote:

maybe you should recheck your project options

Seconded. Check what type of project you are building here:


{"name":"590879","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/2\/5299b9ea9c409a3ad57e66f69b006655.jpg","w":694,"h":347,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/2\/5299b9ea9c409a3ad57e66f69b006655"}590879

It sounds like you have "static library" selected. Most likely you want Console (or perhaps GUI).

Durnus
Member #7,997
November 2006
avatar

Thanks, that worked. I had no clue what I did to change the project type, but that was the problem.

Thanks for all the help, now I can go on programming. I hope I don't have any (many) more problems. :P

Go to: