当我编译我的代码时,我目前收到以下错误:
错误 LNK2019:未解析的外部符号“public: void __thiscall Agent::printSelf(void)” (?printSelf@Agent@@QAEXXZ) 在函数“public: void __thiscall World::processMouse(int,int,int,int)”中引用(?processMouse@World@@QAEXHHHH@Z) World.obj
这是我的代码
代理.h:
class Agent
{
public:
Agent();
void printSelf();
代理.cpp:
void Agent::printSelf()
{
printf("Agent species=%i\n", species);
for (int i=0;i<mutations.size();i++) {
cout << mutations[i];
}
}
GLView.cpp:
void GLView::processMouse(int button, int state, int x, int y)
{
if(world->isDebug()) printf("MOUSE EVENT: button=%i state=%i x=%i y=%i\n", button, state, x, y);
if(button==0){
int wx= (int) ((x-conf::WWIDTH/2)/scalemult-xtranslate);
int wy= (int) ((y-conf::WHEIGHT/2)/scalemult-ytranslate);
world->processMouse(button, state, wx, wy);
}
mousex=x; mousey=y;
downb[button]=1-state;
}
void World::processMouse(int button, int state, int x, int y)
{
if (state==0) {
float mind=1e10;
float mini=-1;
float d;
for (int i=0;i<agents.size();i++) {
d= pow(x-agents[i].pos.x,2)+pow(y-agents[i].pos.y,2);
if (d<mind) {
mind=d;
mini=i;
}
}
if (mind<1000) {
//toggle selection of this agent
for (int i=0;i<agents.size();i++) {
if(i!=mini) agents[i].selectflag=false;
}
agents[mini].selectflag= !agents[mini].selectflag;
agents[mini].printSelf();
setControl(false);
}
}
}
我很困惑。我很长时间没有处理这个代码了,所以我不确定是什么导致了这个。有人看出有什么不对吗?