0

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);
Kad
  • 542
  • 1
  • 5
  • 18
  • Needs more context - where and how is that function used? Is it only unnamed in the declaration or is the parameter really never used? – UnholySheep Jun 09 '18 at 08:45
  • 1
    It means that the argument is unused in the function body but has to be supplied by the caller. You usually encounter this in callbacks, because the caller requires a certain signature. – Henri Menke Jun 09 '18 at 08:46
  • 1
    this https://stackoverflow.com/questions/2319663/why-does-c-code-missing-a-formal-argument-name-in-a-function-definition-compil – wdc Jun 09 '18 at 08:52

2 Answers2

2

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.

Frax
  • 5,015
  • 2
  • 17
  • 19
1

If it's part of a function declaration, it means that it doesn't need to be named yet (e.g. 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. (i.e. to match some function signature).

uv_
  • 746
  • 2
  • 13
  • 25
  • `// in mainwindow.h Q_SIGNALS: void RequestAddListItem(QListWidgetItem *item);` – Kad Jun 09 '18 at 08:49