Inheritance 如何在模板类中使用boost序列化注册类型?
我在尝试序列化模板类的消息时遇到问题。该模板的类消息的类型为BaseClass,但我希望它序列化该类的派生版本。到目前为止,它只是序列化基类。我应该如何向boost::serialization注册我希望它序列化的派生类的类型?我尝试过几种方法,比如使用“BOOST_CLASS_EXPORT”宏。我还尝试使用以下示例:Inheritance 如何在模板类中使用boost序列化注册类型?,inheritance,templates,serialization,boost,Inheritance,Templates,Serialization,Boost,我在尝试序列化模板类的消息时遇到问题。该模板的类消息的类型为BaseClass,但我希望它序列化该类的派生版本。到目前为止,它只是序列化基类。我应该如何向boost::serialization注册我希望它序列化的派生类的类型?我尝试过几种方法,比如使用“BOOST_CLASS_EXPORT”宏。我还尝试使用以下示例: ar.register_type(static_cast<bus_stop_corner *>(NULL)); 从这里开始:但仍然没有运气 template <
ar.register_type(static_cast<bus_stop_corner *>(NULL));
从这里开始:但仍然没有运气
template <class T>
class Frame{
...
private:
T message;
};
class BaseType{};
class SubTypeA : public BaseType{};
class SubTypeB : public BaseType{};
int main(){
std::vector< Frame<BaseType> > myFrames;
//add a bunch of Frame<SubTypeA> and Frame<SubTypeB> objects to the myFrames vector.
//serialize the vector.
return 0;
}
这段代码根本不可编译,但包含它的目的是让您了解我的程序的结构。请确保增强\u类\u导出所有派生类 有关更深入的答案,请参见我对该问题的回答: 这里有一个有效的例子