inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

4.2 전역변수,정적변수~, 헤더파일에 extern을 붙였더니 오류가 났습니다

186

DJ B

작성한 질문수 3

0

main.cpp파일 코드

 

#include <iostream>

#include "Myconstants.h"

using namespace std;

void constants();

int main()

{

cout << "In main.cpp " << Constants::pi << "\t"<< &Constants::pi<<endl;

constants();

return 0;

}

 

test.cpp파일 코드

 

#include <iostream>

#include "Myconstants.h"

using namespace std;

void constants()

{

cout << "In test.cpp " << Constants::pi << "\t" << &Constants::pi<< endl;

}

 

Myconstant.h 헤더파일 코드

#pragma once

namespace Constants

{

extern const double pi(3.14);

extern const double gravity(9.8);

}

 

 

 

 

헤더파일에서 extern을 붙이면 오류가 나고

extern을 빼면 오류가 안나고 잘 실행되는데

이유가 무엇인지 궁금합니다

extern을 붙여서 외부에서 가져다 쓰라고 명시해준건데

오히려 오류가 나는게 왜그런지 모르겠습니다

 

답변 0

환경설정 문

2

32

2

질문있어요!

2

43

2

수업 잘 들었습니다.

2

33

2

volatile에 대해 질문 있습니다.

2

40

2