header.h가비 constexpr 기능 constexpr 변수를 설정 (그러나 컴파일시에 연산 할 수있다)을
extern constexpr double sqrt_of_2;
extern constexpr double sqrt_of_1_2;
double sqrt(double x);
MAIN.CPP
#include <header.h>
int main() {
int n;
scanf("%d", &n);
printf("%lf %lf\n", sqrt_of_2, sqrt(n));
return 0;
}
source.cpp
#include <header.h>
double sqrt(double x) {
// complex bits of math
// huge function
// must not be in header for speedy compilation
// will call other small non-constexpr functions in this file
}
constexpr double sqrt_of_2 = sqrt(2.0);
constexpr double sqrt_of_1_2 = sqrt(0.5)
이것은 분명히 작동하지 않습니다.
source.cpp에 sqrt
에 constexpr
을 추가 할 수 없습니다. header.h의 선언과 일치하지 않기 때문입니다. constexpr
에 inline
이 포함되어 있기 때문에 header.h에 sqrt
에 대해 constexpr
을 추가 할 수 없기 때문에 모든 것을 source.cpp에서 header.h로 전송해야합니다.
이것도 가능합니까?