• Advertisement
Sign in to follow this  

Can't get pointer to point to element of vector found with index.

This topic is 4348 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to point a pointer to an element of a vector:
//vecWindows is a vector full of objects of class CItem
//nIndex is used to directly access the element needed
CItem *pItem=m_vecWindows[nIndex];

But it does not work. Is the a proper way to do this? I have to use the index. Maybe even if I can have an iterator point to the element I want.

Share this post


Link to post
Share on other sites
Advertisement
If the vector stores the items and not pointers you need to do:
CItem *pItem = &m_vecWindows[nIndex];

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement