使用整型提升将所有有符号或无符号的 char、short、枚举类型或位域转换为有符号或无符号的 int。
类类型的所有参数都作为数据结构通过值进行传递;副本是由二进制复制创建的,而不是通过调用类的复制构造函数(如果存在)创建的。
如果使用省略号,则必须在参数列表中最后声明它。
如果函数调用中没有提供值,则可通过默认参数指定参数应采用的值。 以下代码片段演示默认参数的工作方式。
// expre_Ellipses_and_Default_Arguments.cpp
// compile with: /EHsc
#include <iostream>
// Declare the function print that prints a string,
// then a terminator.
void print( const char *string,
const char *terminator = "n" );
int main()
{
print( "hello," );
print( "world!" );
print( "good morning", ", " );
print( "sunshine." );
}
using namespace std;
// Define print.
void print( const char *string, const char *terminator )
{
if( string != NULL )
cout << string;
if( terminator != NULL )
cout << terminator;
}
上面的程序声明一个采用两个参数的函数 print。 而第二个参数 terminator 具有默认值 "n"。 在 main 中,对 print 的前两个调用允许默认的第二个参数提供新行以终止打印的字符串。 第三个调用为第二个参数指定显式值。 该程序的输出为
hello,
world!
good morning, sunshine.
注:相关教程知识阅读请移步到C++教程频道。










