对于可怜的问题标题表示歉意,我不确定该怎么问。尝试编译我的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)
小行星
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();
}
对于解决此问题的任何帮助,我将不胜感激。
谢谢,丹。
最佳答案
在asteroid.cpp文件中,方法声明中缺少类名:
void asteroid::animateAsteroid(){
...