Thread overview | ||||||
---|---|---|---|---|---|---|
|
February 15, 2005 Enums with same names in different classes | ||||
---|---|---|---|---|
| ||||
Attempting to compile the following with DMD 0.113 on Windows results in the error "no property 'Blarg' for type 'int'": ---------------------------------------------------- import std.stdio; class Foo { public: enum MyEnum { Default, Blah } } class Bar { public: enum MyEnum { Default, Blarg } } void main() { writefln("%d", cast(int)Foo.MyEnum.Default); writefln("%d", cast(int)Bar.MyEnum.Default); writefln("%d", cast(int)Foo.MyEnum.Blah); writefln("%d", cast(int)Foo.MyEnum.Blah); // comment out this next line and it will happily compile writefln("%d", cast(int)Bar.MyEnum.Blarg); } ------------------------------------------------------ Commenting out the offensive line (the last writefln) causes it to compile and run, which utterly makes no sense! |
February 15, 2005 Re: Enums with same names in different classes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | Mike Parker wrote: ---------------------------------------------------- class Foo { public: enum MyEnum { Default, Blah } } class Bar { public: enum MyEnum { Default, Blarg } } void main() { writefln("%d", cast(int)Foo.MyEnum.Default); writefln("%d", cast(int)Bar.MyEnum.Default); writefln("%d", cast(int)Foo.MyEnum.Blah); // ooops, this line was wrong in the original // post. Notice that the Bar.MyEnum has no // value named 'Blah' writefln("%d", cast(int)Bar.MyEnum.Blah); // comment out this next line and it will happily compile and run writefln("%d", cast(int)Bar.MyEnum.Blarg); } ------------------------------------------------------ |
February 15, 2005 Re: Enums with same names in different classes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | Mike Parker wrote: [...] > which utterly makes no sense! [...] Congratulation, you downsized the vanishing bug I described in: http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D.bugs/2873 -manfred |
February 19, 2005 Re: Enums with same names in different classes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker Attachments: | Mike Parker wrote: | Mike Parker wrote: | ---------------------------------------------------- | class Foo | { | public: | enum MyEnum | { | Default, | Blah | } | } | | class Bar | { | public: | enum MyEnum | { | Default, | Blarg | } | } | | void main() | { | writefln("%d", cast(int)Foo.MyEnum.Default); | writefln("%d", cast(int)Bar.MyEnum.Default); | | writefln("%d", cast(int)Foo.MyEnum.Blah); | // ooops, this line was wrong in the original | // post. Notice that the Bar.MyEnum has no | // value named 'Blah' | writefln("%d", cast(int)Bar.MyEnum.Blah); | | // comment out this next line and it will happily compile and run | writefln("%d", cast(int)Bar.MyEnum.Blarg); | } | ------------------------------------------------------ Added to DStress as http://dstress.kuehne.cn/run/enum_13.d Thomas |
Copyright © 1999-2021 by the D Language Foundation