I’m trying to make a simple Vector class (math) this way:
template <int D, typename T = float>
class Vector
{
T m[D];
// ...
};
Where D is the number of dimensions. If it is two, the vector will store two values of type T.
How can I declare the constructor function to take D arguments of type T?
Vector<2> v(1.0f, -6.3f);
How to add a function only if D if a specific number? I wish to add GetX() if D is >= 1, GetY() if D is >= 2 and GetZ() if D is >= 3, but the following code should generate a compile-time error:
Vector<2> v(1.0f, -6.3f);
cout << v.GetZ() << endl;
How to generate a compile-time error if D is < 1?
I’m not following any specific standard, anything will work for me.
I don’t have access to a C++11 compiler but maybe something like this could work?