C++:函数重新声明一个未定义的行为?

Say*_*iss 7 c++

码:

#include <iostream>
using namespace std;

int f(int x = 0) {
    cout << "x:" << x << endl;
    return 0;
}
int main() {
    f();
    int f(int x = 1);
    f();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出(在g ++ 5.1上测试):

x:0
x:1
Run Code Online (Sandbox Code Playgroud)

我的问题:

  1. int f(int x = 1);宣言还是定义?
  2. 函数重新声明是不是一个未定义的行为?

Ric*_*ges 14

来自dcl.fct.default中的§8.3.6:

  1. 对于非模板函数,可以在稍后的同一范围内的函数声明中添加默认参数.不同范围内的声明具有完全不同的默认参数集.

不是未定义的行为.你所看到的是强制性的.