저는 초보자이며 객체 생성과 생성자 사이의 관계에 대해 근본적인 의심을 가지고 있습니다. 1클래스의 참조 변수 초기화에 오류가 없습니다.
#include<iostream>
using namespace std;
class xxx{
private: int x;
public: xxx(){cout<<"constructer is called"<<endl;}
};
int main(int argc, char *argv[])
{
xxx x1; //Constructor is called
return 0;
}
출력 - 생성자가 호출 프로그램 -
프로그램 - 2
#include<iostream>
using namespace std;
class xxx{
private: int x;
public: xxx(){cout<<"constructer is called"<<endl;}
};
int main(int argc, char *argv[])
{
xxx x1(); //Constructor xxx() is not called.
return 0;
}
출력 - 빈,상관 정보가 매우 helpfule이다
언급되지 않았으므로 [Most Vexing Parse] (http://en.wikipedia.org/wiki/Most_vexing_parse)라고합니다. –
@CaptainObvlious - 가장 까다로운 구문 분석은 아닙니다. 그것은 단순히 함수 선언입니다. –