参数列表中间是否有默认参数?

| 我在我们的代码中看到了一个函数声明,如下所示
void error(char const *msg, bool showKind = true, bool exit);
我首先认为这是一个错误,因为您不能在函数中间使用默认参数,但是编译器接受了此声明。谁看过这个吗?我正在使用GCC4.5。这是GCC扩展程序吗? 奇怪的是,如果我将其取出到单独的文件中并尝试进行编译,则GCC会拒绝它。我已经仔细检查了所有内容,包括使用的编译器选项。     
已邀请:
如果在函数的第一个声明中,最后一个参数具有默认值,则该代码将起作用,如下所示:
//declaration
void error(char const *msg, bool showKind, bool exit = false);
然后,在同一作用域中,可以在后面的声明中为其他参数(从右侧)提供默认值,如下所示:
void error(char const *msg, bool showKind = true, bool exit); //okay

//void error(char const *msg = 0 , bool showKind, bool exit); // error
可以称为:
error(\"some error messsage\");
error(\"some error messsage\", false);
error(\"some error messsage\", false, true);
在线演示:http://ideone.com/aFpUn 请注意,如果您为第一个参数提供默认值(从左开始),而没有为第二个参数提供默认值,则将无法编译(如预期):http://ideone.com/5hj46 §8.3.6/ 4说,   对于非模板功能,默认   参数可以在以后添加   同一函数的声明   范围。 来自标准本身的示例:
void f(int, int);
void f(int, int = 7);
第二个声明添加默认值! 另请参见§8.3.6/ 6。     
答案可能在8.3.6中: 8.3.6默认参数   6班级成员除外   模板中的默认参数   成员函数定义   出现在课外   定义被添加到   由提供的默认参数   成员函数声明   类定义。默认参数   用于类的成员函数   模板应在   成员的初始声明   类模板中的函数。      例:
class C {
void f(int i = 3);
void g(int i, int j = 99);
};
void C::f(int i = 3) // error: default argument already
{ } // specified in class scope
void C::g(int i = 88, int j) // in this translation unit,
{ } // C::g can be called with no argument
读完这篇文章后,我发现MSVC10在关闭编译器扩展的情况下接受了以下内容:
void error(char const* msg, bool showKind, bool exit = false);

void error(char const* msg, bool showKind = false, bool exit)
{
    msg;
    showKind;
    exit;
}

int main()
{
    error(\"hello\");
}
    

要回复问题请先登录注册