I've found that std::unique_ptr usually works well with messages in C++.
Probably the only case where things get a little bit complicated is if
you're using arena allocation
<https://developers.google.com/protocol-buffers/docs/reference/arenas>,
since in that case the arena owns the message and you must not call delete
on it. Within Google we have a special pointer type that keeps track of
whether a message was arena-allocated or not, and makes sure to call delete
only if the message was heap-allocated.

About inheritance, there is no way to make all messages inherit from a
specified class. However, all messages do inherit from
google::protobuf::MessageLite (and google::protobuf::Message if you're not
using the lite runtime), so that can be useful if you want to write code
that operates on arbitrary message types.

On Thu, Jun 28, 2018 at 12:31 PM John Lilley <whee...@gmail.com> wrote:

> I have two (maybe unrelated) questions:
> -- Is there a recommended way to wrap "smart pointers" around protobuf
> message objects in C++?
> -- Is there a way to make all messages inherit from the same base class or
> interface?  Note I am not trying to make message definitions inherit from
> each other; I only want the classes generated C++ code to inherit from a
> class that I control.'
> Thanks
> john
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at https://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to