0
#include <memory>
#include <deque>

void MyFunc
{
    std::deque< std::shared_ptr< Sprite* > > SpriteList;

    func_to_fill_deque( SpriteList );

    for( auto i = SpriteList.begin(), end = SpriteList.end(); i != end; i++ )
    {
        SpriteList[ i ]->spriteFunc();  // doesn't work
        SpriteList.at( i )->spriteFunc(); // also doesn't work
    }
}

void func_to_fill_deque( std::deque< std::shared_ptr< Sprite* > >& list )
{
    ptr = new Sprite( filename );
    list.push_back( std::make_shared< Sprite* >( ptr ) );
}

When I try SpriteList[ i ] I get a red squiggle under the first '[' with the msg "No operator matches these operands" Trying SpriteList.at( i ) gives a red squiggle under the '.' with the msg "No overloaded function matches the argument list" This is in VS2013 if it matters. Any help would be appreciated.

Edited by jkhippie: #include

2
Contributors
2
Replies
14
Views
2 Years
Discussion Span
Last Post by jkhippie
1

i is not a number. It's an iterator.

Either cycle over the deque using numbers:

for (int i =0; i< SpriteList.size(); ++i)
{
  SpriteList[i] ... ...
}

or dereference the iterator to get at its contents:

 for( auto i = SpriteList.begin(), end = SpriteList.end(); i != end; i++ )
    {
        *i ... ...

Note that since SpriteList is a deque of shared pointers to sprite pointers, *i will give you a shared pointer to a sprite pointer, so (*(*i)) will give you a sprite pointer, so (*(*i))->spriteFunc() will call the function.

Edited by Moschops

Votes + Comments
Beautiful!
1

Awesome! Just what I needed. Why couldn't 10 pages of Bing results find that for me? Leave it to a stuffed dog (?) to have the answer. ;-)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.