简体   繁体   English

未命名函数参数用法

[英]Unnamed function parameter usage

When read some code I saw this unnamed pointer usage as function parameter. 当阅读一些代码时,我看到了这种未命名的指针用法作为函数参数。 What is meaning of this usage ? 这种用法是什么意思?

RequestAddListItem(QListWidgetItem*)

used in this line ( https://socket.io/blog/socket-io-cpp/ ) 在此行中使用( https://socket.io/blog/socket-io-cpp/

connect(this,SIGNAL(RequestAddListItem(QListWidgetItem*)),this,SLOT(AddListItem(QListWidgetItem*)));

Declaration: 宣言:

// in mainwindow.h
Q_SIGNALS:
    void RequestAddListItem(QListWidgetItem *item);

This is not a real C++ syntax. 这不是真正的C ++语法。 SIGNAL() macro will convert it to a string and use it as identifier. SIGNAL()宏会将其转换为字符串并将其用作标识符。 It is used to identify the correct signal to bind to, by matching to signals declarations in Q_SIGNALS section. 通过匹配Q_SIGNALS部分中的信号声明,它用于标识要绑定的正确信号。 This was a chosen convention to use to omit the argument name in these identifiers. 这是一种选择的约定,可用于省略这些标识符中的参数名称。 It is a natural decision, given that these names would tend to be meaningless, with signal/slot name being good enough description. 考虑到这些名称将变得毫无意义,而信号/插槽名称已足够好描述,这是一个自然的决定。

In general, argument names in function declarations are optional, they matter only in function definition, as they are necessary to access the arguments. 通常,函数声明中的参数名称是可选的,它们仅在函数定义中才有意义,因为访问参数是必需的。 Technically, they are still optional. 从技术上讲,它们仍然是可选的。

If it's part of a function declaration, it means that it doesn't need to be named yet (eg in the header). 如果它是函数声明的一部分,则意味着它不需要命名(例如,在标头中)。 If it's part of the function's definition, it means the parameter isn't used. 如果它是函数定义的一部分,则表示未使用参数。

It (the parameter) might need to be declared if this function needs to be an overriding virtual function, a callback that needs to be passed, etc. (ie to match some function signature). 如果此函数需要是一个覆盖的虚拟函数,需要传递的回调等(例如,与某些函数签名匹配),则可能需要声明它(参数)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM