关于狗的类

class Dog
{
DOGCOLOR color;
char name[20];
static int count;
public:
Dog(char name[], DOGCOLOR color)
{
strcpy(this->name, name);
this->color = color;
}
DOGCOLOR getColor()const { return color; }
const char* getName()const { return name; }
const char* getColorString()const
{
switch (color)
{
case BLACK: return "black";
case WHITE: return "white";
case YELLOW: return "yellow";
case BROWN: return "brown";
case PIEBALD: return "piebald";
}
return "motley";
}
void show()const
{
cout << "There is a " << getColorString() << "dog named " << name<<'.' << endl;
}
};

int main()
{
Dog dog1("hoho", WHITE), dog2("haha", BLACK), dog3("hihi", OTHER);
dog1.show();
dog2.show();
dog3.show();
return 0;
}

原文地址:https://www.cnblogs.com/huninglei/p/5461166.html