#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.

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.

commented: Beautiful! +0

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. ;-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.