简体   繁体   中英

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/ )

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. SIGNAL() macro will convert it to a string and use it as identifier. It is used to identify the correct signal to bind to, by matching to signals declarations in Q_SIGNALS section. 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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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