0

I have an issue in my project, where I get use of undefined type AssetManager. I have been stuck with this error for 3 days now.

#pragma once
#include "Components.h"
#include "SDL.h"
#include "Animation.h"
#include "TextureManager.h"
#include "AssetManager.h"
#include"Game.h"
#include <map>
class SpriteComponent :public Component {
private:
    TransformComponent *transform;
    SDL_Rect srcRect, destRect;
    SDL_Texture *texture;
    bool animated = false;
    int frames = 0;
    int speed = 100; 
    int animIndex = 0;
public:
    SpriteComponent() = default;
    std::map<const char*, Animation>animations;
    SDL_RendererFlip spriteFlip = SDL_FLIP_NONE;
    SpriteComponent(std::string id, bool animate) {
        setTexture(id);
        Animation idle = Animation(100, 3, 0),
            walk = Animation(100, 8, 1);
        animations["idle"] = idle;
        animations["walk"] = walk;
        play("idle");
        animated = animate;
    }
    void setTexture(std::string id) {
        texture = Game::assets->getTexture(id);
    }
};

Here is the code of the Game.h, knowing I included AssetManager.h inside Game.cpp:

#include<SDL.h>
#include<iostream>
#include<SDL_image.h>
#include<vector>
class AssetManager;
class Game
{...}
Lorence
  • 13
  • 2
  • 7
  • 1
    Could you please show us the line where the error is reported? – ph3rin Jan 04 '20 at 13:08
  • 1
    Does this answer your question? [When can I use a forward declaration?](https://stackoverflow.com/questions/553682/when-can-i-use-a-forward-declaration) Probably `Game` has a member of type `AssetManager`, which is not defined but only declared. – Lukas-T Jan 04 '20 at 13:15
  • @KaenbyouRin It's in line 35. Game::assets->getTexture(id); – Lorence Jan 04 '20 at 13:19
  • @churill I did refer to this question. It got me to this error, because I included the `AssetManager.h` inside Game.h and things went wild. – Lorence Jan 04 '20 at 13:21
  • @YoussefAlnemr "things went wild" maybe because Game.h has no include guards? And Game.h doesn't include AssetManager.h, so any file that includes Game.h must include AssetManager.h before it, to somehow work. That's no good design => you need to reavaluate your file structure and includes. If you show us the relevant headers we might find a good solution. – Lukas-T Jan 04 '20 at 13:24
  • I forward-declared AssetManager inside Game.h as provided in the snippet above and added `#include"AssetManager.h` in the `Game.cpp`. Is this relevant to circular dependency? https://imgur.com/a/K7y3eUI – Lorence Jan 04 '20 at 13:38
  • @Alnemr The relevant headers would be `Game.h` and `AssetManager.h`. without seing both, it's hard to say anything :/ – Lukas-T Jan 04 '20 at 15:09
  • @churill Thanks for your time and help. It turned out that one of the headers was missing in another .h file *facepalm*. Sorry for all of the hassle. – Lorence Jan 04 '20 at 20:32
  • @Alnemr Good you found the mistake :) – Lukas-T Jan 05 '20 at 09:51

0 Answers0