我一直在试图编译一个多文件项目,但每次我尝试在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