SFML community forums

Help => General => Topic started by: firstep on October 11, 2014, 03:25:43 pm

Title: Code of sfml book?
Post by: firstep on October 11, 2014, 03:25:43 pm
Code of sfml book and the actual tutorial is different?

Im on chapter and i got one error where VS can is saying the my TextureHolder is undefined. I cant figure out how to solve it. I declare all the header on my aircraft.h

But when i look on the code of sfml book there is this ResourceIdentifiers. Its not event mentioned in the book

Here is my whole code
#include "Entity.h"
#include "ResourceHolder.h"
class Aircraft : public Entity
{
public:
        enum class Type{
                Eagle,
                Raptor
        };


        Aircraft(Type type, const this_undefined& textures); <--------- this is the error; its undefined
        virtual void drawCurrent(sf::RenderTarget &target, sf::RenderStates states) const;
       
private:
        Type mType;
        sf::Sprite mSprite;
};
 
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include<assert.h>
#include<map>
#include <iostream>
#include <memory>
using namespace std;

namespace Textures{
        enum class Type{
                Eagle,
                Raptor
        };
}


template<typename Resource, typename Identifier>
class ResourceHolder{
public:
        void load(Identifier id, const std::string &filename);

        template<typename Parameter>
        void load(Identifier id, const std::string &filename, const Parameter &secondParam);

        Resource &get(Identifier id);
        const Resource &get(Identifier id) const;
       

        typedef ResourceHolder<sf::Texture, Textures::Type> this_undenfined;

private:
        std::map<Identifier, std::unique_ptr<Resource>> mResourceMap;
       
};

This is the code im following on the book. But i dont know why the "this_undefined" variable is undefined in my IDE

NOTE: I change it to the word "this_undefined"  to highlight the error
Title: Re: Code of sfml book?
Post by: eXpl0it3r on October 11, 2014, 03:39:49 pm
Yes, the book contains mistakes and the code one can download from the publisher as well, but the complete and working code can be found there (https://github.com/SFML/SFML-Game-Development-Book).

However I'm not really sure what your described problem is, but by comparing the code, you should figure out what's wrong in the book. ;)
Title: Re: Code of sfml book?
Post by: firstep on October 11, 2014, 03:44:15 pm
Im stuck. I tried all that i know. I declare the header file on aircraft.h to be able to get the variable of ResourceHolder.

Another thing is that the code from the link has also this

namespace sf
{
class Texture;
}
namespace Textures
{
enum ID
{
Eagle,
Raptor,
Desert,
};
}
// Forward declaration and a few type definitions
template <typename Resource, typename Identifier>
class ResourceHolder;
typedef ResourceHolder<sf::Texture, Textures::ID> TextureHolder;

which for me doesnt make any sense as it could be declare on resourceHolder alone. So why bother creating another file?
Title: Re: Code of sfml book?
Post by: Nexus on October 11, 2014, 03:58:12 pm
I declare the header file on aircraft.h to be able to get the variable of ResourceHolder.
Please express yourself clearly, I have no idea what you mean. Make sure you're using the correct terms and illustrate the problem with code, if necessary.

which for me doesnt make any sense as it could be declare on resourceHolder alone. So why bother creating another file?
The same reason why functionality is split into different headers elsewhere: a logical structure that allows users to include headers specifically. The header ResourceHolder.hpp contains just the definition of the ResourceHolder class template. There's no reason why the texture IDs should be defined in the same file, if they can as well be included separately.
Title: Re: Code of sfml book?
Post by: firstep on October 11, 2014, 04:23:52 pm
I declare the header file on aircraft.h to be able to get the variable of ResourceHolder.
Please express yourself clearly, I have no idea what you mean. Make sure you're using the correct terms and illustrate the problem with code, if necessary.

What i mean by this is this
#include "Entity.h"
#include "ResourceHolder.h"

Its on the Aircraft class

class Aircraft : public Entity
{
public:
        enum class Type{
                Eagle,
                Raptor
        };


        Aircraft(Type type, const this_undefined& textures);
        virtual void drawCurrent(sf::RenderTarget &target, sf::RenderStates states) const;
       
private:
        Type mType;
        sf::Sprite mSprite;
};

which i was expecting that i could get the this_undefined variable without any errors.