In C++, you can create your own types with the 'class' keyword or the 'enum' keyword. Using the 'class' keyword, the following creates a type Card:
Code:
#include <iostream>
using namespace std;
class Card
{
private:
int x;
double y;
public:
Card()
{
x=10;
y=25.5;
}
void display()
{
cout<<x<<endl
<<y<<endl;
}
};
int main()
{
Card c; //declare a variable of type card
c.display();
return 0;
}
Using the 'enum' keyword, the following creates a type MyException:
Code:
#include <iostream>
using namespace std;
enum MyException
{
exception1,
exception2,
exception3
};
int main()
{
MyException exc; //create a variable of type MyException
exc = exception3; //assign the variable one of the three allowed values
cout<<exc<<endl; //shows that the allowed values are actually equivalent to int values
return 0;
}