파일 분할 관리

 

인프런 Rookiss님의 'Part1: C++ 프로그래밍 입문' 강의를 기반으로 정리한 필기입니다. 
😎[C++과 언리얼로 만드는 MMORPG 게임 개발 시리즈] Part1: C++ 프로그래밍 입문 강의 들으러 가기!

 

 


 

파일 분할 관리

 

Test1.h

#pragma once   // 헤더 파일이 실수로 중복해서 들어가는 상황을 대비해서 적어주자.

// #ifndef _TEST1_H__
// #define _TEST1_H__

struct StatInfo
{
    int hp;
    int attack;
    int defence;
};

void Test_1();

void Test_2();

void Test_3()
{
}

// #endif     // #ifndef, define, endif 방식도 있다.

 

Test1.cpp

#include <iostream>
#include "Test1.h"
using namespace std;

void Test_1()
{
    Test_2();
}

void Test_2()
{
    cout << "Hello World" << endl;
}

void Test_3()
{
}

 

Main.cpp

#include <iostream>
#include "Test1.h"   
// #include "Test1.h"  // 헤더 파일을 복사 붙여넣기 한다는 의미이기 때문에 중복해서 넣으면 안 된다.
                       // 헤더 파일에 #pragma once를 적어서 혹시 모를 실수를 대비하자.
using namespace std;

int main()
{
    Test_2();

    return 0;
}

 

실행화면


 

 

 

#ifndef  ~  #endif

 

#ifndef    _TEST1

#define   _TEST1

 

#endif

 

의미:

#ifndef _TEST1이 정의되지 않았다면 #define _TEST1 으로 정의해라.

#endif 까지 적용된다.