std::map::iterator arithmetic problems

C

Christopher

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top