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

Author Topic: error: no type named value_type in class sf::Rect<int>  (Read 4511 times)

0 Members and 1 Guest are viewing this topic.

Veritas

  • Jr. Member
  • **
  • Posts: 79
    • View Profile
    • Email
error: no type named value_type in class sf::Rect<int>
« on: May 07, 2014, 02:12:58 pm »
When I try to make a vector of sf::IntRects I get the error :

no type named value_type in class sf::Rect<int>

Here is the code:

class Animation
{
public:
        explicit Animation(float);
        void addFrame(sf::IntRect);
        void play();
        void pause();
        void reset();
        void stop();
        void update(float);
        const sf::IntRect& getFrame() const;
private:
        std::vector<sf::IntRect> m_frames;
        float m_duration;
        bool m_playing;
        float m_index;
};

Animation::Animation(float duration) :
        m_frames(),
        m_duration(duration),
        m_playing(true),
        m_index(0)
{
}

void Animation::addFrame(sf::IntRect frame)
{
        m_frames.push_back(frame);
}

void Animation::play()
{
        m_playing = true;
}

void Animation::pause()
{
        m_playing = false;
}

void Animation::reset()
{
        m_index = 0;
}

void Animation::stop()
{
        reset();
        pause();
}

void Animation::update(float dt)
{
        if (m_playing)
        {
                m_index += dt/m_duration;
                if (m_index >= m_frames.size())
                {
                        m_index = 0;
                }
        }
}

const sf::IntRect& Animation::getFrame() const
{
        return m_frames[m_index];
}

Can someone point out what's wrong?
« Last Edit: May 07, 2014, 06:35:12 pm by Veritas »
"Lasciate ogni speranza, voi ch'entrate"

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
Re: error: no type named value_type in class sf::Rect<int>
« Reply #1 on: May 07, 2014, 02:20:18 pm »
Please provide a complete and minimal example. Also provide the line that causes the error.
If you just give an error message, it could've originated from any where, thus you'll make it hard or even impossible to spot a mistake.
Providing only parts of the code, will put the focus on just that code part, while the error might actually happen because of some other code piece that we don't know about.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: error: no type named value_type in class sf::Rect<int>
« Reply #2 on: May 07, 2014, 02:41:14 pm »
Nothing to do with your problem, but there's a logic flaw in your update function:
m_index += dt/m_duration;

Since dt will most likely be always less than m_duration, you'll end up adding 0 all the time and your animation will only ever show the first frame. You should accumulate the elapsed time (either since start, or since last frame changed), and divide the accumulated time by the frame duration to get the frame index.
Laurent Gomila - SFML developer

Veritas

  • Jr. Member
  • **
  • Posts: 79
    • View Profile
    • Email
Re: error: no type named value_type in class sf::Rect<int>
« Reply #3 on: May 07, 2014, 02:57:05 pm »
Yea that's a result of bad variable naming. It's supposed to be the duration per frame. If you set it to 2, the dt that get's added is half of it's actual value. The variables are floats.
"Lasciate ogni speranza, voi ch'entrate"

select_this

  • Full Member
  • ***
  • Posts: 130
  • Current mood: just ate a pinecone
    • View Profile
    • darrenferrie.com
Re: error: no type named value_type in class sf::Rect<int>
« Reply #4 on: May 07, 2014, 03:49:17 pm »
void Animation::Animation(float duration) :
        m_frames(),
        m_duration(duration),
        m_playing(true),
        m_index(0)
{
}
 

You've got void as a return type for the constructor - constructors can't return anything explicitly, even if it's void, as it wouldn't make any sense.

sf::IntRect& getFrame() const;

...

sf::IntRect& Animation::getFrame() const
{
        return m_frames[m_index];
}
 

You're trying to return a non-const reference in a const-qualified function; I would suggest either making the reference const if you intend for the frame to be const, or dropping the const-qualification off the function if you don't (or provide an overload so you can have both options).

Other than that, everything compiles okay, so I think we'll need more detail to find out what's actually causing your specific error.
« Last Edit: May 07, 2014, 06:03:06 pm by ghostmemory »
Follow me on Twitter, why don'tcha? @select_this

Veritas

  • Jr. Member
  • **
  • Posts: 79
    • View Profile
    • Email
Re: error: no type named value_type in class sf::Rect<int>
« Reply #5 on: May 07, 2014, 06:32:25 pm »
Damn. I pasted a function name so I won't have to type the whole constructor and forgot to remove the void. I fixed the const, forgot to edit my post.
« Last Edit: May 07, 2014, 06:38:38 pm by Veritas »
"Lasciate ogni speranza, voi ch'entrate"

 

anything