未命名的函数参数用法

时间:2018-06-09 08:43:56

标签: c++

当读取一些代码时,我将此未命名指针用作函数参数。这种用法的含义是什么?

RequestAddListItem(QListWidgetItem*)

用于此行(https://socket.io/blog/socket-io-cpp/

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

声明:

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

2 个答案:

答案 0 :(得分:2)

这不是真正的C ++语法。 <section id="aboutme"> <div class="container"> <img src="https://vignette.wikia.nocookie.net/fan-fiction-library/images/1/15/Admin.png/revision/latest?cb=20140917130743"> <p>Welcome to my personal website! In here, you will find out everything about me. You can scroll down to discover more about my portfolio, my weekly activities or ways to contact me. Before doing so, I shall briefly introduce myself! I am a 20 year old student studying at Concordia University in Montreal. Currently, I am in my 2nd year of education pursuing a Bachelors in Software Engineering. Up to now, my experience has been wonderful. I meet great people that share similar interests, my network is growing day-by-day and I learn things that interest me. The ultimate goal right now is to graduate and this website will be used to explore everything I learn as I go. For my school assignments and personal projects, you can find them in the <a href="#" class = "intro_link">portfolio</a> section. If you are ever interested in checking out my other social etworks (GitHub, LinkedIn, etc...) or to contact me, you can go to the <a href="#" class = "intro_link">contacts</a> section. </p> </div> </section>宏会将其转换为字符串并将其用作标识符。它用于通过匹配SIGNAL()部分中的信号声明来识别要绑定的正确信号。这是用于在这些标识符中省略参数名称的选定约定。这是一个自然的决定,因为这些名称往往毫无意义,信号/插槽名称就足够了。

通常,函数声明中的参数名称是可选的,它们仅在函数定义中有用,因为它们是访问参数所必需的。从技术上讲,它们仍然是可选的。

答案 1 :(得分:1)

如果它是函数声明的一部分,则意味着它不需要被命名(例如在标题中)。如果它是函数定义的一部分,则表示不使用该参数。

如果此函数需要是一个重写的虚函数,需要传递的回调等等(即匹配某些函数签名),则可能需要声明它(参数)。