I have a question on enum "inheritance" -- I'm wondering if what's happening 
below is a bug or by
design?

I have code like this:

enum AccessMask { GenericRead = 0x80000000 }
enum FileAccess : AccessMask { ReadData = 1 } //Errors
void foo(FileAccess a) { /*Do something*/ }
void bar() { foo(AccessMask.GenericRead); } //Errors

I get two errors:

1. Inside FileAccess, I get an error with the assignment, telling me that it 
can't work implicitly.
If instead of "ReadData = 1" I write "ReadData = cast(AccessMask)1", it works 
fine, but it's a pain.

2. bar() doesn't compile, because it's passing a less specialized value to a 
more specialized one.
While I understand why this wouldn't work from an actual _object_ inheritance 
perspective, I don't
see why this doesn't work in the case of enums -- after all, isn't the subclass 
supposed to contain
every member member of the superclass? Is this by design, and is there a neat 
solution?


Thanks!

Reply via email to