去年作为一名学生,我使用 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/