이 튜토리얼에서는 우리가 직접 작성할 때 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