• Advertisement
Sign in to follow this  

templates and stl iterator syntax error?

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

#include <vector>
#include <map>
#include <utility>

template <class T>
class test
{
	protected:
		std::map<int, T*> thingA;
		std::map<int, float>::iterator thingB_works;
		std::map<int, T*>::iterator thingC_fails;
};
compiling with gcc 3.4 gives: test.cpp:11: error: expected `;' before "thingC_fails" I know its an obvious error but I've looked at it so long I've lost the will to live :) please end my suffering!!

Share this post


Link to post
Share on other sites
Advertisement

typename std::map<int, T*>::iterator thingC_fails;

Share this post


Link to post
Share on other sites
problem solved, thanks!

but why is it that I need to stick that in front of the iterator and not the map?

Share this post


Link to post
Share on other sites
The iterator used :: to get at a nested type of a type dependent on a template parameter. The typename keyword is required to tell the compiler you want to interpret the result of the :: as a type rather than a value.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement