0

我引用了错误 C2995:已定义函数模板,但我不清楚如何解决编译时错误。我没有发现任何circular references错误,因此我想了解编译器生成这些错误的原因。

产生错误的相关代码部分

#ifndef TREE_H_
#define TREE_H_

#include<functional>
#include<vector>

#include<boost/shared_ptr.hpp>

#include <boost/serialization/nvp.hpp>
#include <boost/serialization/split_free.hpp>

#include<boost/serialization/shared_ptr.hpp>

namespace boost { 

     namespace serialization {

         template <class Archive, class T>
         inline void save(
            Archive &archive, 
            const boost::shared_ptr<T> &subtree,  
            const unsigned int file_version
         ){

            // only the raw pointer has to be saved
            const T *subtree_x = subtree.get();

            archive << boost::serialization::make_nvp("raw_pointer", subtree_x);
        }

        template <class Archive, class T>
        inline void load(
            Archive &archive, 
            boost::shared_ptr<T> &subtree, 
            const unsigned int /*file_version*/
        ){

            T *p_subtree;

            // recover the underlying raw pointer
            archive >> boost::serialization::make_nvp("raw_pointer", p_subtree);

            #if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
                subtree.release();
                subtree = boost::shared_ptr< T >(p_subtree);
            #else
                subtree.reset(p_subtree);
            #endif


        }

        template <class Archive, class T>
        inline void serialize(
            Archive &archive, 
            boost::shared_ptr<T> &subtree,  // no const or else get compile-time error
            const unsigned int file_version
        ){

            boost::serialization::split_free(archive, subtree, file_version);
        }


    } // namespace serialization
} // namespace boost

template <class T = int>

class Tree{

    class TreeNode{

        };

 };

 #endif

编译器产生的错误

error C2995: 'void boost::serialization::load(Archive &,boost::shared_ptr<U> &,const unsigned int)' : function template has already been define
error C2995: 'void boost::serialization::load(Archive &,boost::shared_ptr<U> &,const unsigned int)' : function template has already been defined    
error C2995: 'void boost::serialization::load(Archive &,boost::shared_ptr<U> &,const unsigned int)' : function template has already been defined    
error C2995: 'void boost::serialization::save(Archive &,const boost::shared_ptr<U> &,const unsigned int)' : function template has already been defined  
error C2995: 'void boost::serialization::save(Archive &,const boost::shared_ptr<U> &,const unsigned int)' : function template has already been defined  
error C2995: 'void boost::serialization::save(Archive &,const boost::shared_ptr<U> &,const unsigned int)' : function template has already been defined  
error C2995: 'void boost::serialization::serialize(Archive &,boost::shared_ptr<U> &,const unsigned int)' : function template has already been defined   
error C2995: 'void boost::serialization::serialize(Archive &,boost::shared_ptr<U> &,const unsigned int)' : function template has already been defined   
error C2995: 'void boost::serialization::serialize(Archive &,boost::shared_ptr<U> &,const unsigned int)' : function template has already been defined   
4

0 回答 0