Thread View: net.lang.c++
2 messages
2 total messages
Started by David Sher
Sat, 24 May 1986 21:12
Unintuitive semantics for enum
Author: David Sher
Date: Sat, 24 May 1986 21:12
Date: Sat, 24 May 1986 21:12
38 lines
1661 bytes
1661 bytes
I just tripped over another "feature" of c++.
This feature is that enums are not types.
They look like types but really are synonomous with sets of
constant definitions and typedefs of ints. This strikes me as wrong.
Consider this c++ file:
enum footype { FOO = 17 };
void bar ( footype g );
void foo ( footype f )
{
bar ( 13 );
}
overload baz;
void baz ( footype h );
void baz ( int i );
class myclass
{
int k;
public:
myclass ( footype f );
myclass ( int i );
~myclass ( ) { ; }
};
First I think it is wrong that c++ accepts the statement
bar ( 13 )
as good. If bar takes footype's it should not take arbitrary
integers. Note also that the compiler accepts the definition of baz
but refuses the constructor definition of the class. This seems very
odd because either both baz and myclass is ambiguous or both are
unambiguous so the compiler should accept both or reject both.
I know the language is defined this way but the compiler should at
least give warnings when "type violations" of this sort occur.
--
-David Sher
sher@rochester
seismo!rochester!sher
Re: Unintuitive semantics for enum
Author: Andrew Koenig
Date: Sun, 25 May 1986 14:40
Date: Sun, 25 May 1986 14:40
7 lines
856 bytes
856 bytes
> I just tripped over another "feature" of c++. > This feature is that enums are not types. > They look like types but really are synonomous with sets of > constant definitions and typedefs of ints. This strikes me as wrong. Maybe so, but that's how C does it and C++ is just trying to be compatible here.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads