bearophile <bearophileh...@lycos.com> wrote:
Simen kjaeraas:
Here's mine ( 8/11 at compile-time, the remaining at runtime ):
http://ideone.com/6WlFJ
Thank you. It's a nice implementation, and it doesn't use template magic
at all, it's fully OOP :-) Your implementation shows that there are many
different ways to solve this puzzle. I presume a bit shorter code is
possible using templates (as in the 4th C++ version).
I have modified your code a little, I have added the missing 'override',
I have added the required sequence ("there should be a way to handle a
list of animals and the energy of each animal"), but there is no need
for the name field because there is the classinfo.name, and I have
shortened/simplified your (nice) test code a lot:
http://ideone.com/TQzyD
That lacks the compile-time tests, though. The point of writing it the
way I did was to allow runtime tests if the problems were not caught at
compiletime.
What's the purpose of using class names like "wCarrot" instead of
"Carrot"?
Merely that I wanted to call them all objects, and that name was taken.
So I added a random letter, and wanted to keep a consistent naming
convention.
--
Simen