2 ms·
One of the more clever not so well known C++ type system hacks I have seen is the way Ogre3D (a graphics engine for games) handle Degrees versus radians. Basica
by tomjen3 15y ago
One of the more clever not so well known C++ type system hacks I have seen is the way Ogre3D (a graphics engine for games) handle Degrees versus radians. Basically they have a class for each and have overloaded the operators so that you can mix and match operations freely (e.g you get a radian result from some computation which you can then add twenty degrees to simply by saying + Degree(20) and have the C++ type system automatically convert back and forth. And since non virtual classes (think Java classes where all members are final) take no memory and can be trivially inline there is no runtime performance hit at all.
It is a joy to use to.
- Drbble 15y agoDo you mean "members are final" or "classes are final"? A final member is constant, which has nothing to do with inheritance. A final class has no subclasses.
- tomjen3 15y agoAll members are final, and it inherits from nothing -- that way there is no need to store any table of methods with each object as so the size requirement is limited to a single table.
- deleted 15y ago[deleted]