Error: nonstatic member must be relative to object

I'm writing the engine for a game and I'm getting to the part where I start drawing the map and giving textures to objects. But I can't seem to get past this one error. Can anyone help?

This is my Engine.cpp file where I'm getting the error

void Engine::LoadTextures()
{
sf::Texture texture;
texture.loadFromFile("sprite1.png");

TextureManager.AddTexture(texture);

testTile = new Tile(TextureManager.GetTexture(0));
}

This is my TextureManager.h file

#ifndef TEXTURE_MANAGER_H
#define TEXTURE_MANAGER_H

#include <SFML/Graphics.hpp>
#include <vector>
using namespace std;

class TextureManager
{
private:
vector<sf::Texture> textureList;

public:
TextureManager();
~TextureManager();

void AddTexture(sf::Texture& texture);
sf::Texture& GetTexture(int index);

};
#endif

And this is my TextureManager.cpp file

#include "TextureManager.h"
#include <SFML\Graphics.hpp>

TextureManager::TextureManager()
{

}

TextureManager::~TextureManager()
{

}

void TextureManager::AddTexture(sf::Texture& texture)
{
textureList.push_back(texture);
}

sf::Texture& TextureManager::GetTexture(int index)
{
return textureList[index];
}

Any help would be greatly appreciated. I'm about ready to rip my hair out lol
Last edited on
Are you including texturemanager.h into the engine.h file?
Yeah texturemanager is included
Is the object TextureManager defined in class Engine?
In these statements

TextureManager.AddTexture(texture);

testTile = new Tile(TextureManager.GetTexture(0));


TextureManager is not an object. You should create an object of type TextureManager that to call its non-static function members.
Last edited on
Thank you so much! Everything works perfectly now!
Topic archived. No new replies allowed.