After posting a little while ago that I need to brush up on templates (I was trying to export a template class in a DLL iirc) I've started playing with them to see what I can can't do; mostly weird scenarios that I couldn't imagine getting into in the first place.
So I whipped up a Vector class (that actually does nothing right now - just has constructors) which could be used if, for some reason, I didn't want to write Vec2 and Vec3 classes for my game engine.
It's kind of silly and nope, there was little point in posting this.Code:template <const size_t DIMENSIONS, typename T> class Vector { public: Vector(); Vector(T x, ...); private: T mComponents[DIMENSIONS]; }; template <const size_t DIMENSIONS, typename T> Vector<DIMENSIONS, T>::Vector() { for (size_t i = 0; i < DIMENSIONS; i++) { mComponents[i] = static_cast<T>(0); } } template <const size_t DIMENSIONS, typename T> Vector<DIMENSIONS, T>::Vector(T x, ...) { va_list args; int j = x; va_start(args, x); for (size_t i = 0; i < DIMENSIONS, j != -1; i++) { mComponents[i] = j; j = va_arg(args, T); } va_end(args); }
Does anyone even care?
I didn't think so
EDIT: Yes, it compiles but so far the only thing I've done to test it is:
Code:Vector<2, int> vec(0, 0);



LinkBack URL
About LinkBacks




CornedBee