Sunday, February 7, 2016

Day 29: Frustrating Rabbit Hole

Today's work on the assignment led me on a wild goose chase, which I must warn ye about in the future!

IF you make an object, say an array of data types, whose "type" was defined by a strongly typed enum instead of polymorphism, there is no way to avoid switch statements, save for a large array of function pointers. I thought that templated functions could work out, but they only work for constant expressions.

That is, if one wanted to make a templated function and use the enumerated type, one would have to code it so that the enumeration would be known at runtime.

Unless we're specifically supposed to use function pointers, I think I'll stick with the switch statements for now. The Open-Closed Principle may be violated, but there's not much one can do, save for besmirching the assignment and making a set of Datum classes (IntDatum, PointerDatum, etc) which was not part of the assignment. This has felt like a messy assignment, but it may shed some light somewhere down the road.

No comments:

Post a Comment