gcc c++ compiler problems (from 4.0.1 to 4.2.4)

Discussion in 'C' started by michel_dup, May 28, 2008.

  1. michel_dup

    michel_dup New Member

    Joined:
    May 28, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    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 a moderator: May 29, 2008

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice