this
使用关键字时出现链接器错误:
Error 1 error LNK2001: unresolved external symbol "public: virtual void __thiscall GameObject::update(void)" (?update@GameObject@@UAEXXZ) Main.obj Pong C++ Conversion
这是代码
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
类,并且它们的变量在它们的实例之间到处乱飞