C++中的函数签名
C++中的函数签名(function signature):包含了⼀个函数的信息,包括函数名、参数类型、参数个数、顺序以及它所在的类和命名空间。普通函数签名并不包含函数返回值部分,如果两个函数仅仅只有函数返回值不同,那么系统是⽆法区分这两个函数的,此时编译器会提⽰语法错误。函数签名⽤于识别不同的函数,函数的名字只是函数签名的⼀部分。在编译器及链接器处理符号时,使⽤某种名称修饰的⽅法,使得每个函数签名对应⼀个修饰后名称(decorated name)。编译器在将C++源代码编译成⽬标⽂件时,会将函数和变量的名字进⾏修饰,形成符号名,也就是说,C++的源代码编译后的⽬标⽂件中所使⽤的符号名是相应的函数和变量的修饰后名称。C++编译器和链接器都使⽤符号来识别和处理函数和变量,所以对于不同函数签名的函数,即使函数名相同,编译器和链接器都认为它们是不同的函数。
不同的编译器⼚商的名称修饰⽅法可能不同,所以不同的编译器对于同⼀个函数签名可能对应不同的修饰后名称。
For functions that are specializations of function templates, the signature includes the return type. For functions that are not specializations, the return type is not part of the signature.
A function signature consists of the function prototype. What it tells you is the general information about a function, its name, parameters, what scope it is in, and other miscellaneous information.
Two overloaded functions must not have the same signature.
Default Arguments: The last parameter or parameters in a function signature may be assigned a default argument, which means that the caller may leave out the argument when calling the function unless they want to specify some other value.
函数prototype
注:以上内容来⾃于⽹络整理。