공부하고 있는데...소스가 이렇습니다.
주석이나 답글로 설명과 해석 해주실분 ㅠ_ㅠ
파일명 : main.cpp
#include<stdio.h>
#include"str.h"
#include"test.h"
void main(void)
{
#define _xxx
#ifdef _xxx
CStr st1;
CTest st2;
st1.CStr1();
st2.test();
#endif
#ifdef _xxx
printf("아우디n");
#endif
}
파일명 : str.cpp
#include<stdio.h>
#include"str.h"
CStr::CStr(void)
{
printf("str생성자 호출n");
}
CStr::~CStr(void)
{
printf("str소멸자 호출n");
}
void CStr::CStr1(void)
{
printf("str m.mn");
}
파일명 : test.cpp
#include<stdio.h>
#include"test.h"
CTest::CTest(void)
{
printf("Test 생성자 호출n");
}
CTest::~CTest(void)
{
printf("Test 소멸자 호출n");
}
void CTest::test(void)
{
printf("testn");
}
출력결과
str생성자 호출
Test 생성자 호출
str m.m
test
아우디
Test 소멸자 호출
str 소멸자 호출
#include<stdio.h>
#include"str.h"
#include"test.h"
void main(void)
{
#define _xxx // _xxx가 정의(define)한다.
#ifdef _xxx // 만약 _xxx가 정의되어 있다면 밑의 #endif까지 정의해라
CStr st1; // 먼저 CStr의 클래스를 객체 생성
CTest st2; // CTest의 클래스 객체 생성
st1.CStr1(); // 단순 출력??
st2.test();
#endif // 요기까지
#ifdef _xxx // 마찬가지로 _xxx가 정의 되었다면
printf("아우디n");
#endif // 여기까지 포함시켜라.
}
// 먼저 생성된것이 스택의 위에 쌓이므로 소멸자를 먼저 불러옵니다.
//고로 Test의 소멸자가 먼저 불려집니다.