G ++中的显式模板特化

时间:2014-09-03 12:59:06

标签: c++ visual-studio gcc g++

我在这段代码中遇到错误(g ++编译器),但在MSVS编译好。请帮忙解决这个问题。

代码:

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;
    }

错误:

错误:非命名空间范围内的显式特化&#39; struct TicDbx :: FindXerializer&#39;

错误:部分专业化中未使用的模板参数:          struct ImplementedXerializer&lt; 1&gt;

我完成了!!!! 这里解决方案:

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)
    {
        .....

    }

0 个答案:

没有答案