Re: extending c++ classes and enumerations
Alf P. Steinbach skrev:
I'm sorry but I fail to see the relevance to C++ enumeration types, and
having Ellipse inherit from Circle is just as wrong as ever no matter
how the objects are represented internally.
Honesty, I'm not introduced what the elipse-circle problem means in
compiler technology. Is it a mathematical problem? Is it a compiler
implementation problem? Or is it a combination of these factors?
What I was trying to say, was simply that your example
typedef EEx Base;
typedef E Derived;
void foo( Base& v ) { v = e; }
can be overcomed by utilizing templates and a parameter:
bool overflow;
void foo( Base &v ) { v = e; overflow = false}
void foo( Derived &d ) { overflow = true; throw std::logic_error(); }
But of course, back to enumeration derivation, it becomes inconsistency
if the same syntax used to derive classes, is used to inhert sets.
According to my opinion, enumerations not only defines a set and its
elements, but also label a set and its elements. In fact, one could ask
if enums primary goals is to define a set, or if it is used to label
numeric literals.
One could also ask, if say, the enumeration
enum ThreadState{ error = -1, running, terminated };
automatically derives from the set of all (un-labeled) real numbers,
even if it is a hidden derivation. Anyway, the enumeration
1) labels the values -1, 0, 1 with the titles "error", "running",
"terminated" and
2) groups the elements -1, 0, 1 under the abbrevation "ThreadState".
-----
PS. I'm not denying a circle is a special case of an elipse, or that
circles is not a subset of ellipses. I'm just saying that in some
circumstance such as complex analysis, the issue is of minor
importance, where the unit circle (Eulers formula) is used as a base .
What about Fourier series, where most shapes can be expressed as a
linear combination of unit circles? :-) DS.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]