什么是函数的声明和签名之间的区别? [英] what is the difference between function declaration and signature?

查看:1249
本文介绍了什么是函数的声明和签名之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C或C ++函数声明和函数签名之间的区别是什么呢?

In C or C++ what is the difference between function declaration and function signature?

我知道函数声明的东西,但函数签名完全是新的我。什么是具有函数签名的概念呢?什么是用于实际上是两个概念?

I know something of function declaration but function signature is totally new to me. What is the point of having the concept of function signature? What are the two concepts used for actually?

谢谢!

推荐答案

一个函数声明为原型的函数(或它可以来自函数定义如果不是样机在这一点上被视为由编译器) - 它包括返回类型,函数的名称和参数类型(任选℃)。

A function declaration is the prototype for a function (or it can come from the function definition if not prototype has been seen by the compiler at that point) - it includes the return type, the name of the function and the types of the parameters (optionally in C).

一个函数签名是编译器用于执行重载函数声明的部分。由于多个功能可能具有相同的名称(例如,他们在过载),编译器需要一种方法来确定哪几种可能的功能有特定名称的函数调用应解析。签名是编译器认为该重载决议。具体而言,该标准定义了签名为:

A function signature are the parts of the function declaration that the compiler uses to perform overload resolution. Since multiple functions might have the same name (ie., they're overloaded), the compiler needs a way to determine which of several possible functions with a particular name a function call should resolve to. The signature is what the compiler considers in that overload resolution. Specifically, the standard defines 'signature' as:

有关重载决策参与功能的信息:该类型的参数,如果该函数是一个类的成员,简历,资格赛(如有)函数本身和类中的成员函数声明。

the information about a function that participates in overload resolution: the types of its parameters and, if the function is a class member, the cv-qualifiers (if any) on the function itself and the class in which the member function is declared.

请注意,返回类型并不是函数签名的一部分。作为标准说,在一个注脚,函数签名不包含返回类型,因为不参与重载决议。

Note that the return type is not part of the function signature. As the standard says in a footnote, "Function signatures do not include return type, because that does not participate in overload resolution".

这篇关于什么是函数的声明和签名之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆