Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Code of sfml book?  (Read 2524 times)

0 Members and 1 Guest are viewing this topic.

firstep

  • Newbie
  • *
  • Posts: 14
    • View Profile
Code of sfml book?
« 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Code of sfml book?
« Reply #1 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.

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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

firstep

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Code of sfml book?
« Reply #2 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?

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Code of sfml book?
« Reply #3 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

firstep

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Code of sfml book?
« Reply #4 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.


« Last Edit: October 11, 2014, 04:51:40 pm by eXpl0it3r »

 

anything