Quote:
> is there a site that deals with problems when converting from C to C++; i need more info on this because i keep
> finding errors when converting to C++; for example, I want to be able to define an enumeration type; i would then
> like to assign a variable to this type; furthermore I would like to then treat theis variable as an integer; for
> example if the type was Days and contained sunday-> saturday (0 -> 6), I want to be able to define a variable today and
> say today=tuesday; then i would like to say today-1 and have the value of this statement be monday; for some reason I
> could do this in C but not in C++; the help contents say to do some type of dynamic casting; i did that but i still am
> having problems; an example that is similar to my code is:
> today=saturday; -> today=6
> today=(today -1)/3
> any ideas on how I can get my enumeration types to behave like integers?
What you are seeing is a result of C++ being more strongly typed than C.
In C++, when you define an enum, the enum is treated as a user defined
type which is not the same as int. To achieve what you explain above,
try the following:
enum Days
{
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
};
Days today;
today = Friday;
cout << "Today is " << today << endl;
today = static_cast<Days>( static_cast<int>(today) - 1 );
cout << "Today is now " << today << endl;
--
*------------------------------------------------------------
| J. Keith Wedinger
| Technical Specialist - The Limited, Inc.
| http://www.serve.com/uccats
|