Quote:Original post by rip-off
Works for me TM (in both GCC and MSVC)
*** Source Snippet Removed ***
Nice to see some other Irish people around [smile]
[smile]
That code you posted works fine for me too. Wait till you see this though- it's utterly weird:
This is the full header file (so far) for the object:
EditorLevel.h#ifndef EDITOR_LEVEL_H#define EDITOR_LEVEL_H#include <list>class GuiPoint;class EditorLineStrip;class EditorObject;class EditorLevelForce;class EditorMoverObject;class EditorLevelTrigger;class EditorLevelSound;class EditorFXEmitter;using std::list;class EditorLevel{ public: // Destructor: ~EditorLevel(); // Clears the level: void clear(); // Get a list of objects from the level: template<typename T> list<T*> & get(); protected: // Clears a list of level entities template<typename T> void clearList( list<T*> & l ) { list<T*>::iterator i = l.begin(); list<T*>::iterator e = l.end(); while ( i != e ){ delete * i; i++; } } // Level objects list<GuiPoint*> points; list<EditorLineStrip*> strips; list<EditorObject*> objects; list<EditorLevelForce*> forces; list<EditorMoverObject*> movers; list<EditorLevelTrigger*> triggers; list<EditorLevelSound*> sounds; list<EditorFXEmitter*> emitters;};#endif
And here is the source code:
EditorLevel.cpp#include "EditorLevel.h"#include "GuiPoint.h"// DestructorEditorLevel::~EditorLevel(){ clear(); }// Clear the levelvoid EditorLevel::clear(){ // Clear all object lists clearList<GuiPoint>(points); clearList<EditorLineStrip>(strips); clearList<EditorObject>(objects); clearList<EditorLevelForce>(forces); clearList<EditorMoverObject>(movers); clearList<EditorLevelTrigger>(triggers); clearList<EditorLevelSound>(sounds); clearList<EditorFXEmitter>(emitters); // ** TEST: MAKE SURE TEMPLATE SYNTAX IS OK list<GuiPoint*> l = get<GuiPoint>();}// Get a list of objects from the level:template<> list<GuiPoint*> & EditorLevel::get<GuiPoint>(){ return points; }
The code in the source file above produces the C2908 error complaining about the template already being initialized. However.. If I remove this test statement:
// ** TEST: MAKE SURE TEMPLATE SYNTAX IS OKlist<GuiPoint*> l = get<GuiPoint>();
.. Then the code compiles fine. The code also compiles if I move the explicitly instantiated version of
get<>() above where this statement is in the source file.
So it seems that the test statement is initializing the
get<GuiPoint>() version of the template function already, even though I only had a declaration of the template function
in the header file and not an implementation.
This is very odd.. A bug in the compiler perhaps ? Or is it standard C++ behavior ? Weird.. Whatever it is.