Getting "error C2653: 'TextureManager': is not a class or namespace name" despite editing my include statements to fix

Viewed 106

I am getting the error c2653 for the class/ namespace not existing. The file in question is called TextureManager.h, and it contains the class TextureManager, the weird thing is that VS says the class exists and I can use the "go to" button from the right click menu to reach it. But when I go to build, it gives me the error. Also if I close the project and reopen it, it says it is unable to find source file.

This is where I am trying to use TextureManager, the error is being thrown by line 14(the one with TextureManager::LoadTexture())

##pragma once
#include "../TextureManager.h"


class SpriteComponent : public Component
{
private:
    SDL_Texture* texture;
public:

    SpriteComponent(const char* path)
    {
        texture = TextureManager::LoadTexture(path);
    }
};

This is the TextureManager.h

#pragma once
#include "Game.h"

class TextureManager
{
public:
    static SDL_Texture* LoadTexture(const char* fileName);
};

this is the .cpp for it

#include "TextureManager.h"

SDL_Texture* TextureManager::LoadTexture(const char* fileName)
{
    SDL_Surface* tempSurface = IMG_Load(fileName);
    SDL_Texture* tex = SDL_CreateTextureFromSurface(Game::renderer, tempSurface);
    SDL_FreeSurface(tempSurface);
    return tex;
}

the file directory looks something like this (using + for folders and - for files)

+Project
    +Assets
        -some pngs
    +Src
        -Game.cpp
        -Game.h
        -main.cpp
        -Map.cpp
        -Map.h
        -TextureManager.cpp
        -TextureManager.h
        +ECS
            -Components.h
            -ECS.h
            -PositionComponent.h
            -SpriteComponent.h

Edit

To remove all the unnecessary code in the SpriteComponent class as well as the 2 other code samples, I am not sure which part is causing the error.

Someone was mentioning circular includes, textureManager.h does include game.h, which includes components.h, which does include Sprite component, If that is the problem, what would be a good solution, I tried testing for this but while testing other parts broke, so while I didn't get that error I think it was because the file was never needed in the build.

1 Answers

It was the circular includes, so I moved the include for components.h from the game.h to the game.cpp file.

thank you guys.

Related