2013-05-06 117 views
0

我試圖弄清楚爲什麼這段代碼 會在啓動函數返回0時崩潰,boost xml_iarchive當析構函數被調用時崩潰

我懷疑當它從啓動函數返回時,它會調用 析構函數爲xml_iarchive並且它在那裏失敗。

xml_iarchive調用它的析構函數之前,是否必須調用flush或者某個函數來清理之前執行清理操作:。

我不知道,:)

// serialize 
class FileLayout 
{ 

private: 

    std::string m_name; 
    int m_datetime; 
    std::string m_version; 

    std::string m_clientpath; 
    int m_length; 

public: 

    FileLayout() 
    { 

    }; 

    FileLayout(std::string name ,int datetime, 
       std::string version, std::string clientpath, 
       int length) 
    { 
     m_name = name; 
     m_datetime = datetime; 
     m_version = version; 
     m_clientpath = clientpath; 
     m_length = length; 
    }; 

    // Allow serialization to access non-public data members. 
    friend class boost::serialization::access; 

    template<typename Archive> 
    void serialize(Archive& ar, const unsigned version) 
    { 
     ar & boost::serialization::make_nvp("Name", m_name); 
     ar & boost::serialization::make_nvp("DateTime", m_datetime); 
     ar & boost::serialization::make_nvp("Version", m_version); 
     ar & boost::serialization::make_nvp("ClientPath", m_clientpath); 
     ar & boost::serialization::make_nvp("Length", m_length); 
    } 

    // get 

    std::string name() 
    { 
     return m_name; 
    }; 

    int datetime() 
    { 
     return m_datetime; 
    }; 

    std::string version() 
    { 
     return m_version; 
    }; 

    std::string clientpath() 
    { 
     return m_clientpath; 
    }; 

    int length() 
    { 
     return m_length; 
    }; 

}; 


    int Start(std::string &data) // xml 
    { 
    // set filesize 
    // set name 
    boost::iostreams::basic_array_source<char> device(data.c_str(), data.size()); 
    boost::iostreams::stream<boost::iostreams::basic_array_source<char> > s(device); 
    boost::archive::xml_iarchive ia(s,boost::archive::no_header); 

    ia >> BOOST_SERIALIZATION_NVP(filelayout); 

    data.clear(); 

    return 0; // fails here 
    } 

回答

0

原來這是用包裝有問題,我花了整整一天 在這個問題上