Average template

Posted by on August 5, 2009

A tiny template for averaging numbers.
I needed this for a prototype and I didn’t want to “wing it” anymore.

I think there should be a package with similar templates that people could download to enhance the language, I’m just saying… It takes little to come up with this kind of code and in the end it’s always useful to have it around.

You may register it as any numerical type.
Usage example:

You can allocate an instance of the structure with the Create function.
For example, if you registered the template as float, then you may create a dynamic “object” in this way:

Likewise, you should call the Destroy() function to get rid of it.

Trivial but useful. I’m not particularly happy with the naming convention though. But, let’s not forget that this is not an attempt at emulating OOP at all; it’s just a way of giving flexibility to an encapsulated piece of code. For OOP there are proper languages and there is no point whatsoever in trying to emulate it.