Your variable str is a string, but then you try to assign the cerr stream to it. That won't work. Normally, you might have a variable and assign cout or cerr to it as appropriate. In this case, that variable would have to be a reference to ostream, so it is a little more sloppy because you cannot assign to a reference, only initialize it with something. I would suggest something like this:
Code:
if (x.animalType()==2 || x.animalType()==3)
x.print(std::cerr) << endl;
else
x.print(std::cout) << endl;
or this:
Code:
ostream& stream = (x.animalType()==2 || x.animalType()==3) ? std::cerr : std::cout;
x.print(stream) << endl;