#include <iostream>
using namespace std;
class Sample{
public:
enum{ x = 10 };
};
int main(){
cout<<Sample::x<<endl;
return 0;
}
Why x which is enum in class is accessible using scope resolution operator in main function?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I assume you are asking why you do not have to instantiate a
Sampleto accessx. The reason is thatenums are liketypedefs: they create a new type, they don’t create a variable. You can accessSample::xthe same way you could access atypedefor astruct/classdeclaration inside the class.