Advertisement Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views


Recommended Comments

Your library is looking very nice!

However, I have one question. Perhaps I'm just misunderstanding, but why did you not templatize the vector and color classes so you didn't have to rewrite them to accomodate different data types?

Share this comment

Link to comment
Good question.

I thought of using templates for my basic types, but a few things stopped me:

* I don't want newbies to be scared of my library. This is probably a futile thing to attempt, but I'd still like to try [smile]. Templates tend to scare people whom are new to programming or C++.

* I wanted to keep my files more organized. Templates often need to be defined in the same place they are declared. I wanted my header files to be as clean and as small as possible - containing only class definitions and functions that absolutely had to be inlined.

* Some versions of basic types do things that others don't. There aren't as many mathematical operations on integer versions of basic types, for instance. I could just use inheritance for this, but if templates didn't scare the newbies, polymorphic ones sure would [lol]. Also, some operations on different types might screw up. Subtracting components of two Color4ubs might have drastically different results than subtracting components of two Color4fs - one might have negative values. This is something I can explicitly guard against if I keep classes separate.

* There would be a small loss of speed using templates, in that I would have to assume floating point values - maybe even doubles - for most mathematical operations on basic types. That would mean all my integer vectors and colors might incur a lot of implicit conversions.

All in all I probably could've used templates, but I just decided to play it safe and avoid them in this instance.

Thanks for the support!


Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!