-2

I'm new to enum and struct, I'm getting difficulty on how to debug this code. As long as I know, this code is already true and it should output 0 since male is at 0 position inside the gender.

#include <bits/stdc++.h>

using namespace std;

struct Employee{
   int number;
   enum gender{Male,Female};
   enum language{English,Mandarin};
   enum experience{onetofiveyears,fivetotenyears};
}personality;

int main(){
    personality.gender d = Male;
    cout << d;
}

I have no idea on how to fix this. I hope you guys want to help me cause I already did some research and it didn't work. Thank you for your help.

1 Answers1

1

You need to reference the enumeration using scope resolution.

Employee::gender d = Employee::gender::Male;
std::cout << d;
lcs
  • 4,227
  • 17
  • 36
  • What's the difference between :: and dot(.). Yes it has only warning if I use :: but it gives me error if I used dot(.). – truthprogrammer99 Nov 27 '17 at 20:35
  • 1
    `.` refers to members of an object. An enumeration declaration within an object is not itself a member. You can create a member instance of an enumeration, which you can then refer to with the `.`. [More Info](https://stackoverflow.com/questions/4984600/when-do-i-use-a-dot-arrow-or-double-colon-to-refer-to-members-of-a-class-in-c) – lcs Nov 27 '17 at 23:10