使用this
关键字时出现链接器错误:
错误1错误LNK2001:未解析的外部符号" public:virtual void __thiscall GameObject :: update(void)" (?update @ GameObject @@ UAEXXZ)Main.obj Pong C ++转换
这是代码
class GOBall: public GameObject
{
public:
static const GLint SIZE;
static const GLfloat MAX_SPEEDX;
static const GLfloat MAX_SPEEDY;
static const GLfloat DAMPING;
GLfloat velX;
GLfloat velY;
GLfloat startX;
GLfloat startY;
GOBall(GLfloat x, GLfloat y);
void update();
void reverseX(GLfloat center);
void reverseY();
void resetPosition();
};
const GLfloat GOBall::DAMPING = 0.05f;
const GLfloat GOBall::MAX_SPEEDX = 4;
const GLfloat GOBall::MAX_SPEEDY = 8;
const GLint GOBall::SIZE = 16;
GOBall::GOBall(GLfloat x, GLfloat y)
{
this->x = x;//The Error appeared after filling in this function
this->y = y;
this->sx = SIZE;
this->sy = SIZE;
startX = x;
startY = y;
velX = -MAX_SPEEDX;
velY = 0;
}
x变量位于GameObject类
中class GameObject
{
protected:
GLfloat x, y,sx, sy;
public:
virtual void update();
void render();
GLfloat getX();
GLfloat getY();
GLfloat getSX();
GLfloat getSY();
GLfloat getCenterY();
};
有些人可能会注意到我一直试图通过这些教程重新创建Java应用程序Pong,以便更好地掌握OpenGL和C ++的知识 https://www.youtube.com/playlist?list=PL513808FE7D9A5D68
我知道在header / cpp文件中实现这个游戏可能比较容易,但是我首先要把哪个类标题包含在内,因为有四个GameObject
类,并且它们的变量遍布整个地方在他们的实例之间
答案 0 :(得分:0)
该错误通常意味着您忘记实现某个功能(或错过了一个库),并且通常仅在需要时才会出现。
在这种情况下,这意味着未实现方法GameObject::update()
(根update
的{{1}}方法)。如果它是抽象的,那么在声明后添加GameObject
:
=0