4

I have errors in this code (g++ compiler), but in MSVS is compiling good. Please help to solve this problem.

code:

template<class t_Struct, typename T_Xerializer>
    struct FindXerializer
    {
        template <int>
        struct ImplementedXerializer;

        template <>
        struct ImplementedXerializer<1>
        {
            static void load_struct(CTicDbxJob& job, t_Struct& aResult)
            {
                T_Xerializer x(aResult);
                try
                {
                    CTICSerializer::Load(x, job.getTicOptions().internal_getFieldsStore());
                    aResult = x;
                }
                catch(IFieldsStore::baddata_exception&)
                {
                    aResult = t_Struct();
                }
            }
        }
    }



template<class t_Struct, class T_Xerializer>
    bool Xerializer<t_Struct, T_Xerializer>::load_struct(CTicDbxJob& job, t_Struct& aResult)
    {
        FindXerializer<t_Struct, T_Xerializer>::ImplementedXerializer<CanXerialize<T_Xerializer>::Yes >::load_struct(job, aResult);
        return true;
    }

    template<class t_Struct, class T_Xerializer>
    bool Xerializer<t_Struct, T_Xerializer>::save_struct(CTicDbxJob& job, const t_Struct& aData)
    {
        FindXerializer<t_Struct, T_Xerializer>::ImplementedXerializer<CanXerialize<T_Xerializer>::Yes >::save_struct(job, aData);
        return true;
    }

errors:

error: explicit specialization in non-namespace scope 'struct TicDbx::FindXerializer'

error: template parameters not used in partial specialization: struct ImplementedXerializer<1>

I DONE IT!!!! here the solution:

template <class t_Struct, class T_Xerializer, int>
    struct ImplementedXerializer
    {
    };

    template <class t_Struct, class T_Xerializer>
    struct ImplementedXerializer<t_Struct, T_Xerializer, 1>
    {
        static void load_struct(CTicDbxJob& job, t_Struct& aResult)
        {
            T_Xerializer x(aResult);
            .....
        }

        static void save_struct(CTicDbxJob& job, const t_Struct& aData)
        {
            .....
        }
    };

    template <class t_Struct, class T_Xerializer>
    struct ImplementedXerializer<t_Struct, T_Xerializer, 0>
    {
        static t_Struct& get_static()
        {
            .....
        }

        static void load_struct(CTicDbxJob& job, t_Struct& aResult)
        {
            ....
        }

        static void save_struct(CTicDbxJob& job, const t_Struct& aData)
        {
            .....
        }
    };
            ^


template<class t_Struct, class T_Xerializer>
    bool Xerializer<t_Struct, T_Xerializer>::load_struct(CTicDbxJob& job, t_Struct& aResult)
    {
        .....
    }

    template<class t_Struct, class T_Xerializer>
    bool Xerializer<t_Struct, T_Xerializer>::save_struct(CTicDbxJob& job, const t_Struct& aData)
    {
        .....

    }
  • 4
    http://stackoverflow.com/questions/18904587/class-template-specialization-in-class-scope – Drax Sep 03 '14 at 13:07
  • I dont understand what i must to write, please help with this problem? – user3749207 Sep 04 '14 at 10:02
  • 1
    In short, you cannot do what you want as a nested class. You need to put your class outside, or change the design. See the related question: http://stackoverflow.com/q/3052579/1147772 – Drax Sep 04 '14 at 11:25
  • I updated my questions. Where I must to use this static functions. – user3749207 Sep 04 '14 at 12:18
  • 1
    @user3749207 then, why don't you just put `ImplementedXerializer` into global namespace? – ikh Sep 04 '14 at 12:47
  • @ikh, this code was imported from visual studio project. – user3749207 Sep 04 '14 at 15:17
  • @user3749207 whether you imported or not, you can just move it global namespace; And although you use VC++, you should follow C++ standard - otherwise something like this error happens.. – ikh Sep 04 '14 at 22:01
  • If you get it, you can answer yourself and accept it. – ikh Sep 04 '14 at 22:03

0 Answers0