Sign in to follow this  
utilae

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this