Redefinition and Enumerator

前端 未结 2 877
别跟我提以往
别跟我提以往 2020-12-31 06:34

I\'m having a problem with enumerators. Let\'s not waste anyone\'s time, and get straight to it. The error:

1> forgelib\\include\\forge\\socket.h(79): err         


        
2条回答
  •  孤城傲影
    2020-12-31 06:57

    You cannot have equal names in old c-style enums. If you have C++11 - you can use enum class, static constants in classes, different namespaces, or you can simply use different names.

    Example with enum classes

    enum class SocketType
    {
       RAW = SOCK_RAW
    };
    
    enum class ProtocolType
    {
       RAW = IP_PROTO_RAW
    };
    

    example with constants

    struct SocketType
    {
       static const int RAW = SOCK_RAW;
    };
    
    struct ProtocolType
    {
       static const int RAW = IP_PROTO_ROW;
    };
    

提交回复
热议问题