If a pointer is passed to a function for read only, then this pointer is an IN parameter.
If a pointer is passed to a function for read only, but this function makes a copy of the pointer to have access to it in module related functions for read only operations, this pointer is still IN.
If the function still uses the pointer as read only, but the other module related functions use the pointer for write operations, what does that make the pointer? An IN parameter, but without const? An in/out parameter?
Example of what I mean:
class SteeringWheel {
public: float rotation;
public: SteeringWheel(void) {
this->rotation = 0.f;
}
};
class Car {
private: SteeringWheel *steeringWheel;
public:
/**
* @param[?] steeringWheel Is the steering wheel in or in/out?
*/
Car (SteeringWheel *steeringWheel) {
this->steeringWheel = steeringWheel;
}
/**
* @param[in] degree Steering amount in degrees.
*/
void steer(float degree)
{
this->steeringWheel->rotation += degree;
}
};
int main(int argc, char **argv)
{
SteeringWheel steeringWheel();
/* car() uses steeringWheel as read only. */
Car car(&steeringWheel);
/* steer() uses steeringWheel from car() to write. */
car.steer(50.f);
return 0;
}
I believe that the
in
andout
specifiers do not exactly mean what you think. From the doxygen documentation of theparam
tag:The direction of the parameter usually mean the following:
in
: The parameter is injected into the function as input, but not written to.out
: The parameter is injected into the function, but not as input. Rather, it is written to by the function.in, out
: The parameter is injected into the function as input and is eventually written to by the function.In your example:
I think the
steeringWheel
parameter isin
because you inject it and use it in your method. However, you never write to it (i.e. to the parameter itself), so it is notout
. In other words, you only use your method to inject an address to your function, nothing else. The same apply for your second method, where you inject thedegree
parameter, but never write to it.To clarify a bit more on the meaning of
in
andout
, here is an example of anout
parameter:Notice that we write a new value directly into the parameter. This is the meaning of out: information comes out of the method through the parameter. You can now write:
Hope this helps!