From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,9ce095aba33fe8d0 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!g43g2000cwa.googlegroups.com!not-for-mail From: "Hyman Rosen" Newsgroups: comp.lang.ada Subject: Re: Negative float problem Date: 1 Nov 2005 08:04:31 -0800 Organization: http://groups.google.com Message-ID: <1130861070.985832.289890@g43g2000cwa.googlegroups.com> References: <1130351574.313991.229420@g14g2000cwa.googlegroups.com> <10mspnley7gzu$.1swtj67sv0ldr$.dlg@40tude.net> <43677dec$1_1@glkas0286.greenlnk.net> NNTP-Posting-Host: 204.253.248.208 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1130861076 28684 127.0.0.1 (1 Nov 2005 16:04:36 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 1 Nov 2005 16:04:36 +0000 (UTC) In-Reply-To: <43677dec$1_1@glkas0286.greenlnk.net> User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: g43g2000cwa.googlegroups.com; posting-host=204.253.248.208; posting-account=lJDDWg0AAACmMd7wLM4osx8JUCDw_C_j Xref: g2news1.google.com comp.lang.ada:6089 Date: 2005-11-01T08:04:31-08:00 List-Id: Martin Dowie wrote: > Yup, you can't have overloaded enumeration values > I guess because they are really just 'int', so which > one would you mean? No, that's not why. Enumerators have the type of their enumeration. But enumerators go into their enclosing namespace or class, so having multiple ones causes name conflicts. You can actually simulate Ada's approach in C++ by hand, as I show below. You can probably reduce the boilerplate even more by using the Boost preprocessor library, and that would also let you automatically get string versions of the enumerators like Ada has. #include #include struct Color { enum E { Red, Blue }; typedef E (&e)(E); }; struct Traffic_Light { enum E { Green, Amber, Red }; typedef E (&e)(E); }; #define EDEF(C,e) C::E e(C::E = C::e) { return C::e; } EDEF(Color, Red) EDEF(Color, Blue) EDEF(Traffic_Light, Green) EDEF(Traffic_Light, Amber) EDEF(Traffic_Light, Red) void f_c(Color::e v) { std::cout << "Color: " << v(Color::E()) << "\n"; } void f_t(Traffic_Light::e v) { std::cout << "Traffic_Light: " << v(Traffic_Light::E()) << "\n"; } // Notice there are two Reds defined at global scope with no conflict // and that each function is called with the proper Red. int main() { f_c(Red); f_t(Red); }