Another option instead of #ifndef

One thing I’ve learned in the UE4 course that could apply here as well is forward declaring Character* in Enemy then including Character.h in Enemy.cpp, thus making Enemy.h not as bulky to save space in the case that more children files are made down the road

Enemy.h

#include "BaseCharacter.h"

class Enemy : public BaseCharacter

{

    public:

        Enemy(Vector2 pos, Texture2D idleTexture, Texture2D runTexture);

        virtual void tick(float deltaTime) override;

        void setTarget(class Character* newTarget);

    private:

        class Character* target;

};
Enemy.cpp

#include "Enemy.h"
#include "Character.h"

Enemy::Enemy(Vector2 pos, Texture2D idleTexture, Texture2D runTexture)
{
    worldPos = pos;
    texture = idleTexture;
    idle = idleTexture;
    run = runTexture;

    width = texture.width/maxFrame;
    height = texture.height;
}

void Enemy::tick(float deltaTime)
{
    BaseCharacter::tick(deltaTime);
}

void Enemy::setTarget(Character* newTarget)
{
    target = newTarget;
}
1 Like

Privacy & Terms