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 | |
| 5 | BITMAP * interface_bitmap; //It says the error is in THIS LINE. |
| 6 | |
| 7 | bool exit_next_loop = false; |
| 8 | |
| 9 | //Needed to run. |
| 10 | void init(); |
| 11 | void exit_button(); |
| 12 | |
| 13 | //My functions for the interface. |
| 14 | void draw_interface_to_screen(BITMAP*screen); |
| 15 | |
| 16 | int 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 | } |
| 50 | END_OF_MAIN() |
| 51 | |
| 52 | void exit_button() |
| 53 | { |
| 54 | exit_next_loop = true; |
| 55 | } |
| 56 | |
| 57 | void 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 | |
| 12 | class particle //The particle class. Many of there reside in a particlearray. |
| 13 | { |
| 14 | public: |
| 15 | |
| 16 | particle(int type, int x, int y, int particle_size); |
| 17 | particle(); |
| 18 | |
| 19 | int how_close_to(int x, int y); //Returns the distance a bitmap is close to a point. |
| 20 | bool is_point_in(int x, int y); //Returns if a point is in the particle. |
| 21 | |
| 22 | int return_type(); //Returns the type of the particle. |
| 23 | |
| 24 | void calculate(); //Calculates the "physics" of the particle. |
| 25 | |
| 26 | BITMAP* draw_to(); //Draws the particle on specified bitmap. |
| 27 | |
| 28 | private: |
| 29 | |
| 30 | int x_pos; |
| 31 | int y_pos; |
| 32 | |
| 33 | int x_vel; // The x and y velocities. |
| 34 | int y_vel; |
| 35 | |
| 36 | int type; //The particle type. |
| 37 | |
| 38 | } |
| 39 | |
| 40 | |
| 41 | |
| 42 | //The array of particles. |
| 43 | class particlearray |
| 44 | { |
| 45 | public: |
| 46 | |
| 47 | void 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. |
| 48 | void erase_particles(int x, int y, int size); //Erases the particles. |
| 49 | BITMAP* draw_to_screen(); //Draws the particles to the specified bitmap. |
| 50 | |
| 51 | |
| 52 | |
| 53 | private: |
| 54 | |
| 55 | std::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.
sure, paste particle_array.h. just a thought, try <allegro.h> instead of "allegro.h", but that shouldn't really matter..
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
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.
I am sure the allegro library is working.
Yes, there would have been far more errors had you not linked to the library.
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?
->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]
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 : )
You didn't put a semicolon ( ; ) after your class declarations.
class Foo { /*. .. */ } // Wrong class Bar { /* ... */ }; // Right
[edit] Beaten
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. 
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"
i have no idea how Dev-C++ works, but it looks like you are building a library.
maybe you should recheck your project options
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"}
It sounds like you have "static library" selected. Most likely you want Console (or perhaps GUI).
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.