Hello,

Here is a small program that compiles with c++-4.0.1.
I just installed the version 4.2.4 of the gcc c++ compiler.
Now the same code does not compile anylonger and I get message:

"
test_namespace.cpp:15: erreur: specialization of 'T my_namespace::my_struct<T>::get_val() [with T = double]' in different namespace
test_namespace.cpp:15: erreur: from definition of 'T my_namespace::my_struct<T>::get_val() [with T = double]'
test_namespace.cpp:16: erreur: specialization of 'T my_namespace::my_struct<T>::get_val() [with T = float]' in different namespace
test_namespace.cpp:16: erreur: from definition of 'T my_namespace::my_struct<T>::get_val() [with T = float]'
test_namespace.cpp:18: erreur: specialization of 'void my_namespace::my_struct<T>::set_val(T) [with T = double]' in different namespace
test_namespace.cpp:18: erreur: from definition of 'void my_namespace::my_struct<T>::set_val(T) [with T = double]'
test_namespace.cpp:19: erreur: specialization of 'void my_namespace::my_struct<T>::set_val(T) [with T = float]' in different namespace
"

Here is the code:
""
Code:
#include <iostream> 

namespace my_namespace
{
	template <class T>
	struct my_struct 
	{
		public:
		T val;
		T get_val();
		void set_val(T x);
	};
}

template<> double my_namespace::my_struct<double>::get_val(){return val;}
template<> float  my_namespace::my_struct<float>::get_val() {return val;}

template<> void my_namespace::my_struct<double>::set_val(double x){ val=x;}
template<> void my_namespace::my_struct<float>::set_val(float x) { val=x;}

int main()
{
	my_namespace::my_struct<double> toto;
	toto.set_val(10.);
	std::cout << toto.get_val() << "\n";
}
""

I am not good enough to understand why it is not working anymore.
I noticed that it is ok if I move the specializations inside the namespace block.

If somebody could help me it would be great !
Thank in advance.
Sincerely,
Michel

Last edited by shabbir; 29May2008 at 08:45.. Reason: Code block