Domanda

I am getting a linker error when using the this keyword:

Error 1 error LNK2001: unresolved external symbol "public: virtual void __thiscall GameObject::update(void)" (?update@GameObject@@UAEXXZ) Main.obj Pong C++ Conversion

this is the code

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;
}

The x variable is in the GameObject Class

class GameObject
 {
protected:
    GLfloat x, y,sx, sy;
public:
    virtual void update();
    void render();
    GLfloat getX();
    GLfloat getY();
    GLfloat getSX();
    GLfloat getSY();
    GLfloat getCenterY();
};

As some people may notice i have been trying to re-create the Java application Pong via these tutorials in order to better my knowledge in OpenGL and C++ https://www.youtube.com/playlist?list=PL513808FE7D9A5D68

And i know its probably easier to implement this game in header/cpp files but i get confused over which class header to include first, because there are Four GameObject classes, and they have variables flying all over the place between their instances

È stato utile?

Soluzione

That error usually means you forgot to implement a function (or missed a library), and generally only appears when it is needed.

In this case it means that the method GameObject::update() (the update method of the root GameObject) isn't implemented. if it is meant to be abstract then add a =0 behind the declaration:

class GameObject
 {
protected:
    GLfloat x, y,sx, sy;
public:
    virtual void update()=0;
    void render();
    GLfloat getX();
    GLfloat getY();
    GLfloat getSX();
    GLfloat getSY();
    GLfloat getCenterY();
};
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top