Okay... I have understood this question about circular dependency and forward declaration, but I am having trouble understanding a particular error that involve inheritance and pointer-based variables.
I will show snippets of the relevant code:
Player is the derived class from Entity
Entity.hpp
class Entity : public sf::Sprite{
private:
int health;
float speed;
sf::Time spawntime;
bool invincible;
protected:
SceneGame *myScene; // let's keep it at null
// since setScene will take care of it
public:
// more code....
void setScene(SceneGame *scene){myScene = scene;};
SceneGame* getScene(){return myScene;};
};
player.cpp // Assume player.h is complete
myScene is accessible to any classes derived form Entity
void Player::shootPlayer(float dt){
// we reduce time for shoot delay
shootDelay -= dt;
if (shootDelay < 0.0f) return;
resetDelay();
if (Input::instance()->pressKeybutton(sf::Keyboard::Space)){
// I know I set SceneGame* myScene as protected back in Entity class.
// However, because it is claimed to be undefined,
// despite being forward-declared back in entity,
// I'm getting the 'use of undefined type class' error C2027
sf::Texture bulletTex;
bulletTex = (myScene->game->texmgr.getRef("bulletPlayer"));
Bullet* bullet_p = new Bullet(bulletTex,
1, 10, false, false, 0.0f);
bullet_p->setPosition(this->getGlobalBounds().width,
this->getGlobalBounds().height / 2);
}
}
link to answered question: Forward declaration & circular dependency