1 //15-enum type. CPP: The entry point that defines the console application. 2 //3 4#include"stdafx.h"5#include <iostream>6#include <climits>7 using namespacestd;8 9 enumHerotype//enum type is integral. Suitable as tag tag. Ten { OneTank,//0 AMagic,//1 -Adc//2 -Assist//3 the }; - - enumHumantype - { +Teacher =1,//You can modify the values in them -Student =4, +Engineer =5, AFamer =7 at }; - intMain () - { -Herotype herotype = Magic;//defines an enumeration. -Herotype = ADC;//modifies the value of the enumeration. -cout << Herotype <<Endl; in -Humantype Humantype =Famer; to //Try Two enumerations to be able to work together (' contest ') +Auto MyType = Humantype +Herotype; -cout << myType << Endl;//Yes, I can. the * inti = Engineer +3; $cout << i<<Endl;Panax Notoginseng -Herotype = Herotype (2);//after you cast 2 to a custom enumeration type, you can assign a value to the newly defined herotype. thecout << Herotype <<Endl; + //Herotype (2) equals ADC? Acout <<"Herotype:"<< herotype<<endl<<"ADC:"<< ADC << Endl;//are equal! the + //What if it's 10? Can I assign a value to Herotype? -Herotype = Herotype (Ten); $cout << herotype << Endl;//Yes, I can. However, it is best not to write this, the assigned number should have the corresponding enumeration type. $ - //Teacher = Humantype (4);//If you want to assign a value, you have to initialize it first. - the intT; -CIN >>T;Wuyi return 0; the}
C + + Programming Fundamentals 115-enum types