How to use enums in C

0 votes

Suppose we have an enum like the following:

enum Days {Saturday, Sunday, Tuesday, Wednesday, Thursday, Friday};

I want to create an instance of this enum and initialize it with a proper value, so I do:

Days day = Days.Saturday;

Now I want to check my variable or instance with an existing enum value, so I do:

if (day == Days.Saturday)
{
    std::cout << "Ok its Saturday";
}

Which gives me a compilation error:

error: expected primary-expression before ‘.’ token

So to be clear, what is the difference between saying:

if (day == Days.Saturday) // Causes compilation error

and

if (day == Saturday)

?

What exactly do these two terms mean, in that one is OK and the other generates a compilation error?

Jul 7, 2022 in C++ by Nicholas
• 7,760 points
528 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In C++

0 votes
1 answer

How to use std::sort to sort an array in C++

We receive std::begin and std::end in C++0x/11, which are overloaded for arrays: #include <algorithm> int main(){ int v[2000]; ...READ MORE

answered Jun 1, 2022 in C++ by Damon
• 4,960 points
1,137 views
0 votes
1 answer

How to use new[ ] and delete[ ] operator in C++

int main(){ char *str; ...READ MORE

answered Jun 20, 2022 in C++ by Damon
• 4,960 points
566 views
0 votes
0 answers

How to use setprecision in C++

I'm new to C++ and all I want to do is print my point number up to two digits.  For example, if the number is 3.444, the output should be 3.44, and if the number is 99999.4234, the output should be 99999.42.  How am I going to do that?  The value changes over time.  This is my code. #include <iomanip.h> #include <iomanip> int main() { ...READ MORE

Jul 5, 2022 in C++ by Nicholas
• 7,760 points
762 views
0 votes
0 answers

How to traverse stack in C++?

Is traversing std::stack possible in C++? It is not possible to traverse using the following method.  Because there is no member end in std::stack. std::stack<int> foo; // .. for (__typeof(foo.begin()) it = foo.begin(); ...READ MORE

Jun 1, 2022 in C++ by Nicholas
• 7,760 points
2,176 views
0 votes
1 answer

What is the best way to use a HashMap in C++?

The ordered and unordered map containers (std::map and std::unordered map) are included in the standard library.  The items in an ordered map are sorted by key, and insert and access are in O (log n).  For ordered maps, the standard library often use red black trees.  However, this is only an implementation detail.  Insert and access are in O in an unordered map (1).  It is simply another term for a hashtable. An illustration using (ordered) std::map: #include <map> #include <iostream> #include <cassert> int main(int argc, char ...READ MORE

answered Jun 10, 2022 in C++ by Damon
• 4,960 points
831 views
0 votes
1 answer

How to convert string to char array in C++?

Simplest way I can think of doing ...READ MORE

answered Jun 20, 2022 in C++ by Damon
• 4,960 points
5,603 views
0 votes
1 answer

How to use enums in C++

This will be sufficient to declare your ...READ MORE

answered Jun 20, 2022 in C++ by Damon
• 4,960 points
616 views
0 votes
1 answer

setuptools: build shared libary from C++ code, then build Cython wrapper linked to shared libary

There is a seemingly undocumented feature of setup that ...READ MORE

answered Sep 11, 2018 in Python by Priyaj
• 58,020 points
686 views
0 votes
1 answer

setuptools: build shared libary from C++ code, then build Cython wrapper linked to shared libary

There is a seemingly undocumented feature of setup that ...READ MORE

answered Sep 21, 2018 in Python by Priyaj
• 58,020 points
2,384 views
0 votes
1 answer

How to pass large records to map/reduce tasks?

Hadoop is not designed for records about ...READ MORE

answered Sep 25, 2018 in Big Data Hadoop by Frankie
• 9,830 points
1,448 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP