Redefinition error in enumeration (C++)

40 views
Skip to first unread message

Harutaka Matsumoto

unread,
Jul 6, 2020, 4:59:15 AM7/6/20
to Protocol Buffers
Hello everyone!

The question is:
How do I avoid redefinition error with a enumeration values and message's static member functions?

The problem:
I want to implement with following protocol in C++.
```
syntax = "proto3";

message Message {
    enum Enum {
        Clear = 0;
    }
}
```
But I got a following error.
`Redefinition of 'Clear' as different kind of symbol`

It is caused by following two cords.
```
PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final;
・・・
static constexpr Enum Clear =
    Message_Enum_Clear;
```
The former is a static member function of Message.
The latter is a value of Enum.

I'd like to solve this with some options of protoc command like preventing from namespace colluptions, but I couldn't find out.
I wonder you have custom that you name enumeration values with only upper cases.

Adam Cozzette

unread,
Jul 6, 2020, 6:24:32 PM7/6/20
to Harutaka Matsumoto, Protocol Buffers
On Mon, Jul 6, 2020 at 1:59 AM Harutaka Matsumoto <harutaka....@gmail.com> wrote:
I'd like to solve this with some options of protoc command like preventing from namespace colluptions, but I couldn't find out.
I wonder you have custom that you name enumeration values with only upper cases.

Yes, we usually avoid this problem by making sure enum values are all uppercase. That is really the only way to avoid naming conflicts.
 

--
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+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/97234243-8905-4018-9a82-eb9e607eae6dn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages