Jump to content
  • Advertisement
Sign in to follow this  
jhq

a STL question?

This topic is 3889 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 just write a member function for my template class LinkedList<ElementType*>, within which a std::list<ElementType*> is its data member. And I also make this wrapped function InsertBefore, like this
	ElementType* InsertBefore(std::list<ElementType*>::iterator nextElement,
		ElementType* newElement)
	{
		ElementType* pNewElement = new ElementType(*newElement);
		std::list<ElementType*>::iterator iter = m_list.begin();

		m_list.insert(iter, pNewElement);

		return pNewElement;
	}
	

Unfortunately, it cannot work. My VC just indicate that warning C4346: 'std::list<ElementType*>::iterator' : dependent name is not a type prefix with 'typename' to indicate a type error C2061: syntax error : identifier 'iterator' which to me I think is a little bizarre. Isn't the std::list<T>::insert implemented in the same way? Could anyone explain this to me please:)

Share this post


Link to post
Share on other sites
Advertisement
Your warning explains pretty clearly what has to be done:

warning C4346: 'std::list<ElementType*>::iterator' : dependent name is not a type
prefix with 'typename' to indicate a type


Result:

typedef std::list<ElementType*> list_type;
typedef typename MyList::iterator iterator_type;

ElementType* InsertBefore(iterator_type nextElement, ElementType* newElement)
{
ElementType* pNewElement = new ElementType(*newElement);
iterator_type iter = m_list.begin();

m_list.insert(iter, pNewElement);

return pNewElement;
}


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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!