Follow up: Boost serialized custom C++ object passed over ZeroMQ pull socket

故事扮演 提交于 2019-12-05 13:07:01

When I build and run your code on my system, TestBE does throw the deserialization exception (every time). Here's what I did to fix it:

In your ZmqHandler class, change the method void sendToBE(GenericMessage<A> *theMsg) to void sendToBE(GenericMessage<A> theMsg). You can use a const& if you want, but you probably don't want to use a pointer here. In the same method, you need to change theMsg->XXX to theMsg.XXX, since theMsg is no longer a pointer.

In TestFE, zmqHandler.sendToBE(&msg); becomes zmqHandler.sendToBE(msg);.

If theMsg must be a pointer

In ZmqHandler, just change the line archive << theMsg to archive << *theMsg. That way, the archive's operator<< is working with the object, rather than a pointer to the object. The rest of your code can remain the same.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!