Skip to main content
gamedev.net
🔒 Locked

GCC problem with VC++ code

Started by JDX_John 1 reply 850+ views
Original Post
JDX_John
JDX_John
template <class T>
class TemplateClass
{
public:
	typedef std::map<std::string, T*> ObjectList;

	virtual ~ TemplateClass()
	{
		for(ObjectList::iterator it = objects.begin(); it !=objects.end(); ++it)
			delete it->second;
	}
private:
	ObjectList objects;
};
This seemingly innocuous code is fine under VC++ 2008, but breaks under GCC 4 (on the Mac) with errors like "variable 'it' is undefined". It doesn't seem to be pushing the boundaries on what's possible in C++, any thoughts on the problem and possible resolution?
www.simulatedmedicine.com - medical simulation software Looking to find experienced Ogre & shader developers/artists. PM me or contact through website with a contact email address if interested.
jpetrie
jpetrie
Use typename ObjectList::iterator (you may want to typedef this).
rip-off
rip-off
The type iterator is a dependant typename (i.e. it depends on the template parameter). Use the "typename" keyword. IIRC it is required under MSVC too if you disable language extensions.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.