pb开发中遇到的问题

多次析构导致段错误

MergeFrom & CopyFrom

看官方定义 https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.message?hl=en#Message.CopyFrom.details

virtual void Message::CopyFrom(const Message& from)

Make this message into a copy of the given message.

The given message must have the same descriptor, but need not necessarily be the same class. By default this is just implemented as "Clear(); MergeFrom(from);".

给定的消息必须具有相同的描述符,但不一定是相同的类。默认情况下,这只是实现为“Clear(); MergeFrom(from);”。

virtual void Message::MergeFrom(const Message& from)

Merge the fields from the given message into this message.

Singular fields will be overwritten, if specified in from, except for embedded messages which will be merged. Repeated fields will be concatenated. The given message must be of the same type as this message (i.e. the exact same class).

如果在 from 中指定,除了将合并的嵌入消息之外,单个字段将被覆盖。重复的字段将被连接起来。给定的消息必须与此消息具有相同的类型(即完全相同的类)。

最后更新于

这有帮助吗?