+ 8
Hi everyone. Sorry for my english. I would know only one question. What is ENUM in c++?
question
5 Respostas
+ 8
Thanks. I understood. Really helpful comments
+ 5
#include <iostream>
using namespace std;
enum week { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };
int main()
{
week today;
today = Wednesday;
cout << "Day " << today+1;
return 0;
}
OUTPUT:
day 4
i think u can understand from this program. just google it or you can refere it in course if c++ in this app, about defenition and relate with this program.
+ 4
enumeration is a user defined data type that consists of integer constants. you can read more here gives some more info https://en.wikipedia.org/wiki/Enumerated_type
+ 3
one more thing, "enum" ( unscoped ) causes lots of bugs because of the main cause that variables that you declare are global while scoped enum the variables are local.
you should be using "enum class" ( scoped ) in C++.
ex .
enum Unit { Alpha, Beta, Gamma };
Unit u;
u = Alpha; // Alpha is global
int Alpha = 63; // Compiler generates errors
enum class Unit { Alpha, Beta, Gamma };
Unit u;
u = Unit::Alpha; // Alpha is local
int Alpha = 63; // Compiles fine.
I would recommend to read "Effective Modern C++" for more information about it.
+ 1
An enumeration is a user-defined data type that consists of integral constants. To define an enumeration, keyword enum is used.
enum season { spring, summer, autumn, winter };