我们自己编写时,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 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短