我们有很多原生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