如果将指针传递给只读函数,则该指针是 IN 参数。
如果一个指针被传递给一个只读函数,但是这个函数复制了一个指针以便在模块相关函数中访问它以进行只读操作,这个指针仍然是 IN。
如果函数仍然使用指针作为只读,但其他与模块相关的函数使用指针进行写操作,那么指针是什么?一个 IN 参数,但没有 const?输入/输出参数?
我的意思的例子:
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;
}