SFML community forums

Help => Graphics => Topic started by: BiiXteR on January 11, 2016, 06:58:54 pm

Title: [SOLVED] - sf::Sprite is not a drawable?
Post by: BiiXteR on January 11, 2016, 06:58:54 pm
So, currently I have this :


std::map<std::string, sf::Sprite*> sprites;


and I loop trough it like this :
        for (auto const& i : sprites)
        {
                window->draw(i.second);
        }
 
But when I try to run it, it tells me that :

illegal indirection
 void sf::RenderTarget::draw(const sf::Vertex *,size_t,sf::PrimitiveType,const sf::RenderStates &)': cannot convert argument 1 from 'sf::Sprite *const ' to 'const sf::Drawable &

Reason: cannot convert from 'sf::Sprite *const ' to 'const sf::Drawable'
No constructor could take the source type, or constructor overload resolution was ambiguous



Note :
I'm pretty new to both C++ and SFML so it might be obvious.
It might not even be a SFML problem.
 :P
Title: Re: sf::Sprite is not a drawable?
Post by: G. on January 11, 2016, 07:13:05 pm
The draw function accepts sf::Sprite, but not pointers to sf::Sprite. And i.second is a pointer to an sf::Sprite.
You need to dereference your pointer.
window->draw(*i.second);
Title: Re: sf::Sprite is not a drawable?
Post by: BiiXteR on January 11, 2016, 07:49:03 pm
The draw function accepts sf::Sprite, but not pointers to sf::Sprite. And i.second is a pointer to an sf::Sprite.
You need to dereference your pointer.
window->draw(*i.second);

I could have sworn I already tried that... But anyways, it worked!  :)
Thank you!

Also, new to this forum, do you know how accepting/marking an answer works?
Title: Re: sf::Sprite is not a drawable?
Post by: zsbzsb on January 11, 2016, 07:54:41 pm
Also, new to this forum, do you know how accepting/marking an answer works?

This forum doesn't have that option, but if you want you can put '[SOLVED]' in the title of the thread (edit the first post).