Accessing attributes in functions within the class returns wrong values

  attributes, c++, class, glm-math, object

I have a constructor

GameObject::GameObject(Node body){
    _body = body; 

    glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f);
    glm::vec3 velocity = glm::vec3(0.0f, 1.0f, 0.0f);

};

and a member function

void GameObject::update(float dt) {
    this->position = this->position + this->velocity * dt;
}

After calling the constructor, I call the update function on the same object.

GameObject* go_water = new GameObject(water);
go_water.update(dt);

However, if I use debug mode in visual studio and a breakpoint within the update method, I see that this->positions contains all "-431602080.". Why is this?

Source: Windows Questions C++

LEAVE A COMMENT