Sign in to follow this  

basic iterator problem

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

Hi. I want to convert the iterator to my type qvec. I tried static_cast, but seems it doesnt like. Any help will be appreciated. Regards Kazz
		
	for(int i = 0; i < 3; i++)
	{
		std::vector<qvec>::iterator itr  = std::find(mVB.begin(), mVB.end(), *arr[i] );
		if(itr == mVB.end())
		{
			mVB.push_back(*itr);
		}
		else
		{
			//qvec* p = (qvec*)itr;  //ERROR.Error	2	error C2440: 'type cast' : cannot convert from 'std::_Vector_iterator<_Ty,_Alloc>' to 'qvec *'

		}
	}

Share this post


Link to post
Share on other sites
An iterator is not a pointer. If you need a pointer, dereference the iterator to get a reference to the object, then use the address-of operator to get a pointer. In other words, &*iter.

Share this post


Link to post
Share on other sites

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