1

I want to use a reserverd name, which is "const" in my enum.

    public enum class EdsAttributeAccessType : int
    {
        ro,
        rw,
        wo,
        const,
        notSpecified
    };

Is it possible to do this or just an illegal use? The reason why I am trying to do this is I am parsing a device description file where this appears. The easiest way is to parse the file's attribute like this.

File example:

...
[2F51sub2]
ParameterName=Program Number 2
ObjectType=0x07
DataType=0x0007
AccessType=rw
DefaultValue=0x0
PDOMapping=0

[2F59]
SubNumber=3
ParameterName=Download Timeout Indicator
ObjectType=0x08

[2F59sub0]
ParameterName=Number of Entries
ObjectType=0x07
DataType=0x0005
AccessType=const
PDOMapping=0
...

Then I just have to do this:

EdsNodeAttribute^ result = FindAttribute(EdsAttributeType::AccessType);

if (result != nullptr){
   return (EdsAttributeAccessType)Enum::Parse(EdsAttributeAccessType::typeid, result->Value, true);
}
EdChum
  • 376,765
  • 198
  • 813
  • 562
Frodo
  • 749
  • 11
  • 23
  • In C# there is something like a prefix '@' to use the reserved names. See http://stackoverflow.com/questions/91817/whats-the-use-meaning-of-the-character-in-variable-names-in-c – Frodo Nov 09 '15 at 15:36

1 Answers1

2

Chapter 9.1.1 in the C++/CLI language spec (Ecma-372) tells you how to do it. Use the __identifier keyword:

public enum class EdsAttributeAccessType : int
{
    ro,
    rw,
    wo,
    __identifier(const),
    notSpecified
};
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536