Hi,
I have an array of object RCStickAxis called myAxes..
I have a function which should return a single element of it, taking the id as argument.
I want to check for indexOutOfBounds. If I am out of bounds, I want to return null, otherwise I want to return the myAxis element.
I have following function in a class:
RCStickAxis RCStick::getAxis(unsigned char axis)
{
// check bounds
if (axis >=0 && axis < sizeof (myAxes))
{
// we are in bounds
return myAxes[axis];
}
else
{
Log.fatal(F("RCStick::getAxis(unsigned char axis) requests stick which is out of bounds. Requested: %d, valid is 0 to %d. Returning NULL!\n"), axis, sizeof(myAxes)-1);
return NULL;
}
}
When trying to compile I get following error:
..\RCStick.cpp:33:10: error: could not convert '0' from 'int' to 'RCStickAxis'
return NULL;
^
subdir.mk:34: recipe for target 'RCStick.cpp.o' failed
make: *** [RCStick.cpp.o] Error 1
What am I doing wrong or how do I implement it better? Try catch around the call from the outside?
Thanks, Andreas