0

I referenced error C2995: function template has already been defined but it was not clear to me how my compile-time errors could be resolved. I did not discover any circular references and thus I would like to understand why the compiler generates these errors.

The relevant portion of code where the errors are generated

#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

The errors generated by the compiler

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   
Community
  • 1
  • 1
Mushy
  • 2,535
  • 10
  • 33
  • 54
  • 3
    You are defining function templates that are already defined by boost. How do you want to resolve this situation? – n. m. could be an AI Apr 22 '13 at 16:05
  • By removing the boost namespace declaration and resolving `error C2995` succeeded. Please turn your comment into an answer. – Mushy Apr 22 '13 at 16:56

0 Answers0