본문 바로가기

Modern C++

C++ 코드의 실행은 main() 함수부터인가요?

 

Modern C++ 은 실제로 C++11 부터 시작한다고 봐야겠죠?

그때부터 이미 구조체는 생성자를 지원하고 있었습니다......(난 최근까지 기억에 없었다 몰랐거나 무시했거나)

아무튼 그래서,

Hello World 를 찍어보려고 하는데요.

실제로 실행코드는 main() 함수부터 실행이 되나요?

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
 
struct iamStruct
{
    iamStruct() {
        std::cout << "I am the Struct Before main() function!!" << std::endl;
    }
};
 
iamStruct theKing;
 
int main()
{
    std::cout << "Hello World!\n";
}
cs

 

실제로 실행 결과를 보면,

1
2
3
I am the Struct Before main() function!!
Hello World!
 
cs

아무래도 그렇지는 않은 것 같군요.