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

C:函数是否重新声明了一个未定义的行为?,第1张

概述码: #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;} Output(在g 5.1上测试): x 码:
#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;}

Output(在g 5.1上测试):

x:0x:1

我的问题:

>是int f(int x = 1);声明或定义?
>函数新声明是否像未定义的行为?

解决方法 从 dcl.fct.default的§8.3.6开始:
For non-template functions,default arguments can be added in later declarations of a function in the
same scope. Declarations in different scopes have completely distinct sets of default arguments.

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

总结

以上是内存溢出为你收集整理的C:函数是否重新声明了一个未定义的行为?全部内容,希望文章能够帮你解决C:函数是否重新声明了一个未定义的行为?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1242598.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存