我一直在玩C,C++和Allegro感謝一本小書和一本我在Oxfam書店發現的大書。 我理解它是相當不錯的時刻,但我已經打了一堵牆......每當我編譯我得到這些錯誤:C++(貌似)隨機編譯器錯誤
[email protected]:~/Documents/C++ Projects/particles$ g++ particles.c -lalleg -lnoise -o particles
particles.c:19: error: array bound is not an integer constant before ‘]’ token
particles.c:20: error: ‘Vector2D’ does not name a type
particles.c:21: error: ‘Vector2D’ does not name a type
particles.c: In function ‘int main()’:
particles.c:26: error: ‘nPos’ was not declared in this scope
particles.c:28: error: ‘nVel’ was not declared in this scope
particles.c:29: error: ‘nvel’ was not declared in this scope
particles.c:31: error: ‘addParticle’ was not declared in this scope
particles.c: At global scope:
particles.c:47: error: ‘Vector2D’ has not been declared
particles.c:47: error: ‘Color’ has not been declared
particles.c: In function ‘void addParticle(int, int, Vector2d, int, int, int)’:
particles.c:50: error: ‘particles’ was not declared in this scope
這是我的代碼...
#include "allegro.h"
struct Vector2d{
double x;
double y;
};
struct Particle {
Vector2d Pos;
Vector2d Vel;
int age;
int LifeSpan;
int colour;
int size;
};
int max = 50;
int pcount = 0;
Particle particles[max];
int main(void) {
Vector2D nPos;
Vector2D nVel;
nPos.x = 320;
nPos.y = 240;
nVel.x = 2;
nvel.y = 0;
addParticle(10, nPos, nVel, 20, makecol(255,255,255), 2);
allegro_init();
install_keyboard();
set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0);
while(!key[KEY_ESC]) {
for(int i=0;i<pcount;i++){
}
}
allegro_exit();
}
void addParticle(int addp, Vector2D Pos, Vector2d Vel, int LifeSpan, Color colour, int size) {
for(int i=0;i<addp;i++){
pcount++;
particles[pcount].Pos = Pos;
particles[pcount].Vel = Vel;
particles[pcount].LifeSpan = LifeSpan;
particles[pcount].colour = colour;
particles[pcount].size = size;
}
}
END_OF_MAIN();
從我從調試輸出中收集到的第一個錯誤是關於 '粒子粒子[最大]'的問題;'這條消息聽起來像是在'粒子'的末尾有這個'[max]'是錯誤的,但是直到現在,這個工作正常並且編譯沒有問題。這可能只是一個錯字或誤解,但我真的無法弄清楚。
正如你可以看到它是在一個粒子系統的要求,並在砥礪任何提示(就是一個字?)我的代碼是極大的讚賞:)
感謝。
嘗試宣告最大爲'const int的最大值= 50' –
'Vector2D'或'Vector2d' ......選擇一個...;) –
這個問題被標記C++和C,但問題是問關於C++而文件名稱表示C. C++和C是兩種不同的語言。您還將該文件編譯爲C++。挑一個...... – bames53