Hello fellow daniwebians.
Consider the following constructor:
Vector3f::Vector3f(float* f)
{
x = *f;
f++;
y = *f;
f++;
z = *f;
}
Now let's create an object of the Vector3f class
//Create an object of Vector3f
Float f[] = {13,3,7};
Vector3f myVector(f);
All is well right ?
Now let's say I make a mistake
float f[] = {3,2};
Vector3f myVector(f);
So I am passing an incomplete array to the constructor.
What will happen is either that the z-coordinate will be all wrong or the program will cause a null pointer exception.
So my question is, how do I from within the constructor verify that the length of the array is at least 3 ?
I was thinking you could add another argument asking for the sizeof the array, but that seem a bit redundant doesn't it ?