What is the right way to use access a value in an enumeration in C++

  c++, enums, mingw

I have come across this while coding and I am not sure about why its the way It is.
Consider this code

Case 1

#include<iostream>

enum test{
a,b,c,d,e,f
};

int main(){
    std::cout << a;
    return 0x1;
}

Case 2

#include<iostream>

enum test{
a,b,c,d,e,f
};

int main(){
    std::cout << test::a;
    return 0x1;
}

Why does the code compile and execute properly for both? Is using test:: not necessary while using enumerations?

Source: Windows Questions C++

LEAVE A COMMENT