function pointer as the enum base type
mumba
qniol at o2.pl
Sun Oct 5 16:21:09 PDT 2008
Idea: to make an enum type with function pointers as it's elements.
Problem: no more than one element can be inserted!
$echo '
void foo() {}
void bar() {}
enum Enum : void function() {
FOO = &foo,
BAR = &bar
}
int main() { return 0; }' > enum.d
$dmd --help
Digital Mars D Compiler v2.014
Copyright (c) 1999-2008 by Digital Mars written by Walter Bright
Documentation: http://www.digitalmars.com/d/2.0/index.html
...
$dmd enum.d
enum.d(5): Error: Integer constant expression expected instead of (& bar) < (& foo)
enum.d(5): Error: Integer constant expression expected instead of (& bar) > (& foo)
I don't understand the error message.
First - why integer constant expression expected, if it's supposed to be the function based enum? Second - instead of what? (& bar) expression, which is smaller than (& foo), or boolean expression (& bar) < (& foo)?
Third - in both cases: if only one of these messages appeard - it would be just strange for me. But as they are together and both refer to the same line - I'm knocked out. What logic leads to such mutually exclusive pieces of information?
Please someone explain it to me.
By the way:
enum Enum : void function() {
FOO = &foo
}
works fine.
cheers
More information about the Digitalmars-d-learn
mailing list