我们自己编写时,C ++编译器会创建默认构造函数吗?
在本教程中,我们将讨论一个程序,以了解在编写自己的程序时C++编译器是否创建了默认构造函数。
通常,C++编译器在未定义默认构造函数的情况下使用默认构造函数,但始终使用用户定义的默认构造函数。
示例
#include<iostream>
using namespace std;
class myInteger{
private:
int value;
//other functions in class
};
int main(){
myInteger I1;
getchar();
return 0;
}输出结果
Compiles successfully
示例
#include<iostream>
using namespace std;
class myInteger{
private:
int value;
public:
myInteger(int v) //user-defined constructor
{ value = v; }
//other functions in class
};
int main(){
myInteger I1;
getchar();
return 0;
}输出结果
Gives error about user-defined constructor not being defined
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短