In C++, is a constructor with only default arguments a default constructor?(在 C++ 中,只有默认参数的构造函数是默认构造函数吗?)
问题描述
在以下代码中:
struct Foo
{
Foo(int x=0);
};
构造函数算作默认构造函数吗?
Does the constructor count as a default constructor?
推荐答案
C++98 §12.1/5 (强调我的):
C++98 §12.1/5 (emphasis mine):
类 X 的默认构造函数是无需参数即可调用的 X 构造函数.如果类 X 没有用户声明的构造函数,则隐式声明默认构造函数.
A default constructor for a class X is a constructor of X that can be called without an argument. If there is no user-declared constructor for class X, a default constructor is implicitly declared.
所以是的,它确实算作默认构造函数.另见.
So yes, it does count as a default constructor. See also.
这篇关于在 C++ 中,只有默认参数的构造函数是默认构造函数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C++ 中,只有默认参数的构造函数是默认构造函数吗?


- C++ 协变模板 2021-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 静态初始化顺序失败 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 近似搜索的工作原理 2021-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 从python回调到c++的选项 2022-11-16