Web Developer wrote:
Hi,
Java doe not have the data type enum. I am starting to learn it in Java and
find it confusing.
1) Whats the point in having enum? Java does have it, so probably there is a
way around it.
No.
2) Can someone show a SIMPLE code of how enum works?
Yes.
#include <iostream>
enum vote { no, yes };
std::ostream& operator <<(std::ostream& os, vote v) {
return os << (!v ? "no" : "yes");
}
vote operator or(vote lhs, vote rhs) {
return vote(lhs | rhs);
}
int main() {
std::cout << (yes or no) << std::endl;
}
Well, try also this:
#include <cstdio>
#include <climits>
//#include <iostream>
int main() {
enum { iMIN = LONG_MIN, uMAX = ULONG_MAX } ld = iMIN, lu = uMAX;
printf("%ld ** %lu\n", LONG_MIN, ULONG_MAX);
printf("%ld ** %lu\n", static_cast<signed long>(ld),
static_cast<unsigned long>(lu));
// std::cout << ld << " ** " << lu << std::endl;
}
regards,
alexander.