GLUT游戏中的C ++ LNK 2019错误

时间:2012-11-25 17:20:51

标签: c++ glut lnk2019

对于糟糕的问题标题道歉,我不知道如何问这个问题。我在尝试编译我的GLUT游戏时遇到了LNK2019错误,我无法发现导致错误的原因。

错误: main.obj:error LNK2019: unresolved external symbol "public: void __thiscall asteroid::animateAsteroid(void)" (?animateAsteroid@asteroid@@QAEXXZ) referenced in function "void __cdecl idle(void)" (?idle@@YAXXZ)

asteroid.h

class asteroid
{
public:
asteroid(void); //constructer
~asteroid(void); //deconstructer

void Draw();
void createAsteroid();
float generateAsteroidLocation(float a, float b);
void animateAsteroid();
};

asteroid.cpp(故障功能)

#include "asteroid.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <ctime>
#include <GL/glut.h>

float asteroidX,asteroidY, V;
bool locationGenerated = false;

asteroid::asteroid(void){

}

asteroid::~asteroid(void){

}
void animateAsteroid(){
float dt = 3500;
float Dx = 25 - asteroidX;
float Dy = 25 - asteroidY;
float Cx = asteroidX + Dx / sqrt(Dx*Dx+Dy*Dy) * V * dt;
float Cy = asteroidY + Dy / sqrt(Dx*Dx+Dy*Dy) * V * dt;
asteroidX = Cx;
asteroidY = Cy;
}

Main.cpp(我收到错误的函数)

void idle(void)
{
glutPostWindowRedisplay(glutGetWindow());
Asteroid.animateAsteroid();
}

我非常感谢您解决此问题的任何帮助。

谢谢,Dan。

1 个答案:

答案 0 :(得分:1)

在asteroid.cpp文件中,您缺少方法声明中的类名:

void asteroid::animateAsteroid(){
...