我们自己编写时,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
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短