Originally posted by: kalster
enum is basically a type istelf, well collection but collection of valyes,, by default the values start from zero , so item 1 =0 , item 2 =1, and so on, you can typcase an unsigned char value, to the enum though
Originally posted by: Vertimus
How do i define the data type of an enumeration?
For example, in
enum Foo {
item1,
item2,
item3,
item4,
};
I want to make it "unsigned char" or something
Any ideas?
Originally posted by: statik213
Originally posted by: Vertimus
How do i define the data type of an enumeration?
For example, in
enum Foo {
item1,
item2,
item3,
item4,
};
I want to make it "unsigned char" or something
Any ideas?
You can't change the type of an enum.... enum's are essentially int's, you can do this though:
enum Foo {
item1 = 32,
item2 = 12989,
item3 = 'a',
item4,
};
char c = (char) item3;
If you want to do funky stuff with enum's i.e. have varies properties you can use the enum design pattern, outlined here for java:
http://www.javaworld.com/javaworld/jw-07-1997/jw-07-enumerated.html
You should be able to do something like that in c++....
type is the underlying type of the identifiers. This can be any scalar type, such as signed or unsigned versions of int, short, or long. bool or char is also allowed.
Originally posted by: Amol
enums are ints
if you have:
enum foo{item1, item2, item3, item4};
if you do:
cout<<item1<<endl; it will display 0.
Originally posted by: Vertimus
Originally posted by: statik213
Originally posted by: Vertimus
How do i define the data type of an enumeration?
For example, in
enum Foo {
item1,
item2,
item3,
item4,
};
I want to make it "unsigned char" or something
Any ideas?
You can't change the type of an enum.... enum's are essentially int's, you can do this though:
enum Foo {
item1 = 32,
item2 = 12989,
item3 = 'a',
item4,
};
char c = (char) item3;
If you want to do funky stuff with enum's i.e. have varies properties you can use the enum design pattern, outlined here for java:
http://www.javaworld.com/javaworld/jw-07-1997/jw-07-enumerated.html
You should be able to do something like that in c++....
MSDN says differently though...
Text
type is the underlying type of the identifiers. This can be any scalar type, such as signed or unsigned versions of int, short, or long. bool or char is also allowed.
Maybe this works only on microsoft compilers? I can't find anywhere else that says or disproves this.
Edit: added link
Originally posted by: Vertimus
Originally posted by: Amol
enums are ints
if you have:
enum foo{item1, item2, item3, item4};
if you do:
cout<<item1<<endl; it will display 0.
Can you please find somewhere that says that? I want to make sure, since the msdn site says differently.
Thanks
Originally posted by: statik213
Originally posted by: Vertimus
Originally posted by: statik213
Originally posted by: Vertimus
How do i define the data type of an enumeration?
For example, in
enum Foo {
item1,
item2,
item3,
item4,
};
I want to make it "unsigned char" or something
Any ideas?
You can't change the type of an enum.... enum's are essentially int's, you can do this though:
enum Foo {
item1 = 32,
item2 = 12989,
item3 = 'a',
item4,
};
char c = (char) item3;
If you want to do funky stuff with enum's i.e. have varies properties you can use the enum design pattern, outlined here for java:
http://www.javaworld.com/javaworld/jw-07-1997/jw-07-enumerated.html
You should be able to do something like that in c++....
MSDN says differently though...
Text
type is the underlying type of the identifiers. This can be any scalar type, such as signed or unsigned versions of int, short, or long. bool or char is also allowed.
Maybe this works only on microsoft compilers? I can't find anywhere else that says or disproves this.
Edit: added link
AFAIK enums are always ints... but the MSDN article is intersting.... according to it, you can do:
enum foo : double{
x1 = 0.3,
x2 = 0.4,
x3 = 0.5
};
never seen this before....
what is it that you are trying to do?
Since the default is int, you can always cast to (char) or (unsigned char).....

 
				
		