Sign in to follow this  

Whats wrong with my std::vector iterator?

This topic is 4383 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

Hello - This looks to me like it should work: std::vector<cServerObject*>::iterator iter = m_objectList.begin(); for(; iter < m_objectList.end(); iter++) { WCHAR* tempName = iter->getName(); OutputDebugString( tempName ); } where m_objectList is std::vector<cServerObject*> and cServerObject has a function GetName(), returning a WCHAR* as requested! I am getting : error C2839: invalid return type 'std::vector<_Ty>::_Tptr' for overloaded 'operator ->' with [ _Ty=cServerObject * ] Please help, thanks!!! :) simon

Share this post


Link to post
Share on other sites
Quote:
Original post by sipickles
std::vector<cServerObject*>::iterator iter = m_objectList.begin();

for(; iter < m_objectList.end(); iter++)
{
WCHAR* tempName = iter->getName();
OutputDebugString( tempName );
}



Since your stored type is a pointer, you need something like this instead:

WCHAR* tempName = (*iter)->getName();

Good luck!

[Edit - ACK! Too slow!]

Share this post


Link to post
Share on other sites
You should also do:

for(; iter != m_objectList.end(); iter++)

instead of:

for(; iter < m_objectList.end(); iter++)

Since comparing iterators using < is not guaranteed to work.

Share this post


Link to post
Share on other sites

This topic is 4383 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.

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