extern
키워드 변수에서 많이 쓴다
다른 파일에서 해당변수를 참조하기 위해서 사용하게 된다
// stdafx.h : 자주 사용하지만 자주 변경되지는 않는
// 표준 시스템 포함 파일 및 프로젝트 관련 포함 파일이
// 들어 있는 포함 파일입니다.
//
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
// TODO: 프로그램에 필요한 추가 헤더는 여기에서 참조합니다.
#include <iostream>
using namespace std;
//헝가리안표기법 g_ 붙이기
extern int g_iTest;
////////////////////////////////
extern.cpp
/////////////////
#include "stdafx.h"
#include "Test.h"
int g_iTest = 0;
int g_iTest2 = 0;
void Test(void)
{
++g_iTest;
}
void Render(void)
{
cout << g_iTest << endl;
Test();
}
int _tmain(int argc, _TCHAR* argv[])
{
Render();
cout << g_iTest << endl;;
cout << g_iTest2 << endl;;
//다른 영역의 파일에서도 글로벌하게 사용이 가능하다
//개꿀
return 0;
}
댓글