Tuesday, April 25, 2006

POD casting....

I was playing with C++ POD types today (which stands for "plain old data"). These are funny little classes that are only a single item, and this item is enough to fit inside a CPU's register. Theres some limits to these classes, but if you use them right, they're quite cool and ideal for things like Handles, CRCs, IDs, Indexes and the like. It must be public, and you cant have any constructors or overloaded == operators. Aside from that, its a fairly normal class. Very neat.
This was all part of my drive to understand templates, and in doing this, Russell and I figured out how to use these POD types correctly. He had thought he was using them right before, but it turns out that although he'd tested it, he had then added stuff that made it a plain old class again. Problem is, the compiler doesn't tell you it just switches, and the only way to know for sure is to disassemble the code and see what its using!
Anyway, I'm starting to get the hang of templates on a rudimentary level at least and while I'm still a long way off from using them in anger, at least I can now follow code that does use them - almost.

No comments: