c++ - GCC 4.2.x 是否创建构造函数?

标签 c++ gcc constructor g++

去年作为一名学生,我使用 GCC 4.4.7 编译 C++ 代码,如果它们没有在代码中明确定义,它会为我的类创建构造函数和析构函数。这是版本 4.2.x 中存在的功能吗?

在你问之前,是的,我用谷歌搜索了这个并查看了 gcc.gnu.org,但我的搜索结果一无所获。

最佳答案

如果没有用户生成的构造函数/析构函数,那么将为您提供一个。

C++11 标准 § 12.1.4(构造函数)

A default constructor for a class X is a constructor of class X that can be called without an argument. If there is no user-declared constructor for class X, a constructor having no parameters is implicitly declared as defaulted (8.4). An implicitly-declared default constructor is an inline public member of its class.

C++11 标准 § 12.4.4(析构函数)

If a class has no user-declared destructor, a destructor is implicitly declared as defaulted (8.4). An implicitlydeclared destructor is an inline public member of its class.

关于c++ - GCC 4.2.x 是否创建构造函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31482306/

相关文章:

gcc - 如何使用 GCC 5.1 和 OpenMP 将工作卸载到 Xeon Phi

C 程序 - 错误 : type mismatch with previous external decl of ‘char line []’ [-fpermissive]\

c++ - 构造函数和析构函数必须是虚的?

c++ - 根节点以上内容的 Qt xml 文件问题

c++ - 'this' 是否保证指向 C++ 中对象的开头?

c++ - C++ 如何用 void 调用 ifstream?

c - 如何在 C 中手动迭代堆栈帧?

python - self 参数在功能上为什么不同?

c++ - 复制构造函数问题

c++ - OpenCV 背景分割/从单个图像中减去