std::map::iterator arithmetic problems

Discussion in 'C++' started by Christopher, Jan 13, 2009.

  1. Christopher

    Christopher Guest

    I don't understand why I am getting errors on this code. My goal is to
    access a map by index and I find no appropriate method, so I tried
    this:

    const D3DXMATRIX & Material::GetMatrix(const unsigned index,
    std::string & name)
    {
    if( index < 0 || index > m_matrices.size() - 1 )
    {
    throw BaseException("Invalid index requested",
    "const D3DXMATRIX & GetMatrix(const unsigned
    index, std::string & name)",
    "Material.cpp");
    }

    Matrices::const_iterator it = m_matrices.begin();
    it = it + index; // Error here!
    it->second;
    // snip
    }


    where I have the following typedefs in the header


    template <class T>
    struct Attribute
    {
    bool m_initialized;
    T m_value;
    };


    /**
    * Map of matrix attributes
    *
    * key - matrix variable name as it appears in the DirectX effect
    * value - Attribute structure containing the matrix
    */
    typedef std::map<std::string, Attribute<D3DXMATRIX> > Matrices;
    Matrices m_matrices;




    Anyone know how to achieve my goal?
    I want to pretty much allow another specific class access to the
    entire map, I just don't want to expose the details,
    so I attempted this access by index along with a get size combination,
    which isn't working.
     
    Christopher, Jan 13, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Jansson
    Replies:
    5
    Views:
    6,317
    Ivan Vecerina
    Mar 17, 2005
  2. Replies:
    6
    Views:
    652
    Jim Langston
    Oct 30, 2005
  3. Replies:
    1
    Views:
    428
    red floyd
    Dec 21, 2008
  4. Thomas J. Gritzan
    Replies:
    6
    Views:
    1,025
    James Kanze
    Dec 22, 2008
  5. James Kanze
    Replies:
    0
    Views:
    2,006
    James Kanze
    Dec 21, 2008
Loading...

Share This Page