documentation - 这是一个 in 或 in/out 参数吗? Doxygen,C++

标签 documentation doxygen inout

如果将指针传递给只读函数,则该指针是 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;
}

最佳答案

我相信 inout 说明符并不完全符合您的想法。来自 doxygen documentation of the param tag :

The \param command has an optional attribute, (dir), specifying the direction of the parameter. Possible values are "[in]", "[in,out]", and "[out]", note the [square] brackets in this description. When a parameter is both input and output, [in,out] is used as attribute.

参数的方向通常含义如下:

  • in:参数作为输入注入(inject)到函数中,但不写入。
  • out:参数被注入(inject)到函数中,但不作为输入。相反,它是由函数写入的。
  • in, out:参数作为输入注入(inject)到函数中,并最终由函数写入。

在您的示例中:

/**
* @param[?] steeringWheel Is the steering wheel in or in/out? 
*/
Car (SteeringWheel *steeringWheel) {
    this->steeringWheel = steeringWheel;
}

我认为 steeringWheel 参数是 in 因为您注入(inject)它并在您的方法中使用它。但是,您永远不会写入它(即参数本身),因此它不是out。换句话说,您只使用您的方法将地址注入(inject)到您的函数中,仅此而已。这同样适用于您的第二种方法,您在其中注入(inject) Degree 参数,但从不写入它。

为了进一步阐明 inout 的含义,下面是 out 参数的示例:

/**
 * @param[out] p_param We write to the parameter!
 */
void makeFour(int * p_param)
{
    *p_param = 4; // Out because of this line!
}

请注意,我们直接将新值写入参数中。这就是out的含义:信息通过参数从方法中出来。您现在可以编写:

int main()
{
    int myInt = 0;
    std::cout << myInt;    // prints 0.

    makeFour(&myInt); // p_param == &myInt here.
    std::cout << myInt;    // prints 4: the method wrote directly 
                           // in the parameter (out)!

    return 0;
}

希望这有帮助!

关于documentation - 这是一个 in 或 in/out 参数吗? Doxygen,C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47732665/

相关文章:

c++ - 如何交叉引用现有的 doxygen 文档?

swift - swift inout参数是变量还是指针?

swift - 在实例函数中初始化实例变量

angular - 如何用 Angular 编写我的函数的文档

doxygen - 我可以编写类似于 @code 或 @verbatim 的 doxygen 别名吗?

linux - Linux/GTK 上存在哪些应用程序帮助系统(如 chm 文件)?

versioning - "New API In version A.B.C"在 doxygen 中的页面

ios - 不能在 inout 函数中使用 SKShapeNode

javascript - 在哪里可以找到有关 Javascript 引擎内部结构的信息?

c - 对 doxygen 使用 lint 注释