[英]C++: is function re-declaration a undefined behavior?
碼:
#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;
}
輸出 (在g ++ 5.1上測試):
x:0
x:1
我的問題:
int f(int x = 1);
聲明或定義? 來自dcl.fct.default中的§8.3.6 :
- 對於非模板函數,可以在稍后的同一范圍內的函數聲明中添加默認參數。 不同范圍內的聲明具有完全不同的默認參數集。
不是未定義的行為。 你所看到的是強制性的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.