Hey,
I know that working out the size of an array is a common question, but mine's slightly different.
I'm working on a fairly big C++ project and am new to the language, but from previous experience I've been programming defensively - i.e. checking all parameters to member functions and such.
One example of this is checking that an array isn't too big or too small when it is provided. Here's the kind of thing I've been doing:
CODE
MyClass::MyClass(int *arrThings, unsigned int iNoVals)
{
for (unsigned int i=0; i<iNoVals; i++)
{
if (!arrThings[i])
{
throw Exception("Problem! The array provided to the MyClass constructor was too small for the provided size.");
}
// Validate individual value here
}
if (arrThings[i])
{
throw Exception("Problem! The array provided to the MyClass constructor was too large for the provided size.");
}
}
I have a feeling that this isn't right, but I've busted my project so it won't compile for the moment, and so can't test it properly. Is this the case?
Thanks,
-Joe