I understand, but how come this links and compiles without error or warning (all warnings enabled) in Visual C++ 2008 and not g++?
This does actually compile if I have all the files in a single build project, but I really want the SmartEnum. as just an include header for use in other projects.
This class is only supposed to be inherited from afaics.
Ok, I created a SmartEnum.cpp class and added template <> Enum<int>::Instances_list Enum<int>::s_instances and this compiled successfully into a libray file.
However in the Smart_Enum project when I add the library to the project and include the .h file I still get the same errors any ideas?
Got this working eventually with a lot of faffing about.
In the end made the following changes to SmartEnum.h
changed s_instances to be a pointer
added this to the constructor
if (!s_instances)
{
s_instances = new instances_list;
}
This change to SmartEnum.cpp
template<class T>
typename Enum<T>::instances_list *Enum<T>::s_instances = 0;
This to Smart_Enum.cpp
template <class T> typename Enum<T>::instances_list *Enum<T>::s_instances = 0;
I found this info from this post
http://webui.sourcelabs.com/gcc/mail/user/threads/Initialization_of_a_static_member_of_a_template_class_fails.meta
The main thing is that it works :)
I have SmartEnum and Smart_Enum built as a libraries
and main referencing LibSmart_Enum_Test.a by explicitly adding this library to the linker and only using the header file.
This was a good learning experience for me and I have gained some valuable knowledge that different compilers deal with templates in different ways, IMHO I think Visual C++ provides the best implementation by far.
Thanks for your help
Not so confused