我一直在試圖編譯一個多文件項目,但每次我嘗試在player.cpp中使用void時,我都會收到此錯誤消息,在編譯過程中創建的player.o具有void player_action(...)的相同定義。當我嘗試在其他文件中使用void時,會出現相同的問題,並帶有相應的.o文件。但是,如果我在任何文件中使用結構體,則不會發生任何問題,並且不會發生「多重定義」錯誤。下面的代碼是編譯器給我的錯誤信息。編譯打嗝在C++和.o文件
obj\Debug\player.o: In function `Z13player_actioniii':
D:/Projects/Blackmail Mailman/player.cpp:13: multiple definition of `player_action(int, int, int)'
obj\Debug\main.o:D:/Projects/Blackmail Mailman/player.cpp:13: first defined here
這是player.cpp我使用的代碼:
#include "include_files.cpp"
struct player_struct
{
int x;
int y;
int previous_x;
int previous_y;
int mode;
};
void player_action(int x, int y, int mode)
{
SDL_Event event;
if (SDL_PollEvent(&event))
{
if (event.type == SDL_KEYDOWN)
{
switch(event.key.keysym.sym)
{
case SDLK_RIGHT:;
};
};
};
};
出了什麼問題,我該如何解決?我在Mingw和Windows XP中使用了Codeblocks。我已經檢查過其他文件,並且沒有任何void player_action()的額外定義。
這是什麼意思「使用void」? – 2011-12-14 01:56:44
它意味着使用這樣的東西:void player_action(int x,int y){...}。 – Ripspace 2011-12-14 01:58:24