我們有很多原生C++類,使用boost :: serialization完美地序列化。是否可以使用託管類的boost :: serialization?
現在,我們希望他們的一些成員字段更改爲財產,這樣我們就可以在PropertyGrids使用它們。當我們改變了類definiction到引用類X,我們得到了這些編譯錯誤的一個巨大的數字:
#1: error C2893: Failed to specialize function template 'boost::archive::text_oarchive &boost::archive::detail::interface_oarchive<Archive>::operator <<(T &)' d:\someAddress\someFile.cpp 58
#2: error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const std::_Smanip<_Arg> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'boost::archive::text_oarchive' d:\someAddress\someFile.cpp 58
我們有很多的這裏的小班,所以爲他們每個人寫一個包裝將是一件痛苦的事情!
下面是我們使用的示例類:
ref class gps_position2
{
public:
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & seconds;
}
public:
gps_position(){};
gps_position(float s)
{
this->seconds = s;
}
property float seconds;
};
這裏是主要的測試代碼:
int main()
{
std::ofstream ofs("out.txt");
gps_position2 g(24.567f);
// save data to archive
{
boost::archive::text_oarchive oa(ofs);
// write class instance to archive
oa << g;
}
// ................
return 0;
}
它甚至有可能使用的boost ::系列化與管理類?
編輯:
如果我們改變了類使用的代碼如下:
...
gps_position2^ g = gcnew gps_position2(24.567f);
...
那麼我們只能得到1個錯誤:
error C2027: use of undefined type 'boost::STATIC_ASSERTION_FAILURE<x>' D:\path\to\Boost\boostw\boost\archive\detail\check.hpp 60
問題仍然發生時,該屬性被刪除(但類仍然是一個ref類)? – CiscoIPPhone 2010-10-31 10:58:25
您可以使用.NET序列化嗎? C++和C++ - cli不是同一種語言。雖然它們可以在一定程度上混合,但對於C++而言,增強並非C++ - cli。 – 2010-10-31 11:13:02
@CiscolPPhone:是的,它仍然存在。 @Merlyn Morgan-Graham:不,我們必須在主代碼(使用本機C++)中使用boost:serialization,這個代碼只是主程序的一個工具。 – Sayyid 2010-10-31 11:13:23