SFML community forums

Help => General => Topic started by: Tomaszlek on January 28, 2018, 07:30:33 pm

Title: Trouble with textures
Post by: Tomaszlek on January 28, 2018, 07:30:33 pm
That's my first topic on this forum and I have trouble with this error and I don't know how it fix.
There's the code:
#include <stack>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include "game.h"
#include "game_state.h"
#include "texture_manager.h"
using namespace sf;
void Game::loadTextures()
{
    menedzertekstur.loadTexture(background, "RTS/tlo_menu.png");
}
and
void TextureManager::loadTexture(const std::string& name, const std::string& filename)
{
    /* Load the texture */
    sf::Texture tex;
    tex.loadFromFile(filename);

    /* Add it to the list of textures */
    this->textures[name] = tex;
    return;
}
public:

    /* Add a texture from a file */
    void loadTexture(const std::string& name, const std::string &filename);
class Game
{
private:
    void loadTextures();

    public:
    stack<GameState*> states;

    RenderWindow window;
    TextureManager menedzertekstur ;
    Sprite background;
Title: Re: Trouble with textures
Post by: eXpl0it3r on January 28, 2018, 07:38:14 pm
And what's the error/issue? :)
Title: Re: Trouble with textures
Post by: Tomaszlek on January 28, 2018, 08:09:55 pm
The error is: no matching function for call to 'TextureManager::loadTexture(sf::Sprite& const char[17])
Title: Re: Trouble with textures
Post by: eXpl0it3r on January 28, 2018, 08:47:00 pm
You declared loadTexture as private member function, thus it's not accessible from the outside.
Title: Re: Trouble with textures
Post by: Tomaszlek on January 28, 2018, 09:41:25 pm
So what should I change in this code because I don't know(I've learned C++ since 4 months and SFML since 2 weeks but I know I'm stupid)
Title: Re: Trouble with textures
Post by: eXpl0it3r on January 28, 2018, 10:22:44 pm
Go back to just C++ and learn more. In 4 months you have barely touched the basics. If you don't know the difference between a public and private member function, then there's more to learn first, before diving into a library that requires you to have a basic understanding of C++.

I can't stop you from playing around with SFML, but keep in mind that the SFML forum isn't here to teach you C++, it's not even here to teach you SFML, but it's here to help you and support you using SFML. Plus the huge catalog of threads may give you solutions to problems you may run into.
For general C++ questions use StackOverflow or similar.

As for your problem, get your C++ book and read or hopefully re-read the section about access specifiers. ;)
Title: Re: Trouble with textures
Post by: Tomaszlek on January 28, 2018, 11:08:30 pm
Well, your advice will help me,maybe it's too early for me to write games in SFML, surely I go back to my C ++ book (very good indeed, written by Jerzy Grębosz). I have already understand the error in the code and I fixed it but I think it's better that I have to learn C ++ for about next half a year and then start writing games seriously. Thank you and best regards