I'm trying to figure out how do i print a distinct enum value by using a conditional statement in my construction of array.
I have a enum declaration
enum Animal {Rat, Ox, Tiger, Rabbit, Dragon, Snake, Horse, Sheep, Monkey, Rooster, Dog, Pig};
And i construct my array using a voidptr
void constructSet(VoidPtr* animalArray, int size)
{
int k = 0;
for(int i = 0; i < size; i++)
{
animalArray[i] = getAnAnimal();
while ((k < i) || (animalArray[i] == animalArray[k]))
{
if (animalArray[i] == animalArray[k])
animalArray[i] = getAnAnimal();
k++;
}
}
}
Then i have to use some static cast to revive the value of my enum
VoidPtr getAnAnimal()
{
VoidPtr anAnimal;
Animal *a = new Animal;
int k = rand() % 12;
*a = static_cast<Animal>(k);
anAnimal = a;
return anAnimal;
}
Unfortunately, they still return me the same values.