Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- //enum - это просто набор констант
- enum Test{
- //объявление со значением по умолчанию
- VALUE = 5
- };
- class StateClass
- {
- public:
- //перечисляемый тип enum
- enum PCState
- {
- ON,
- OFF,
- SLEEP
- };
- //сеттер, принимает константу енума PCState
- void SetState(PCState State)
- {
- this->State = State;
- }
- //геттер
- PCState GetState()
- {
- return State;
- }
- private:
- PCState State = PCState::OFF;
- };
- int main(int argc, char *argv[])
- {
- setlocale(LC_ALL, "Rus");
- srand(time(NULL));
- StateClass st;
- st.SetState(StateClass::PCState::SLEEP);
- switch(st.GetState())
- {
- case StateClass::PCState::ON:
- std::cout << "ON" << std::endl;
- break;
- case StateClass::PCState::OFF:
- std::cout << "OFF" << std::endl;
- break;
- case StateClass::PCState::SLEEP:
- std::cout << "SLEEP" << std::endl;
- break;
- }
- std::cout << "\n\n" << Test::VALUE;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement