Jump to content
  • Advertisement
Sign in to follow this  
sipickles

Whats wrong with my std::vector iterator?

This topic is 4690 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!