我们自己编写时,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 出嫁条幅伴娘祝福语简短