티스토리 뷰

Coding

Visual Studio 2015 error C2668

duckchan.seo 2016. 10. 31. 00:44

Visual studio 2015 이전 버전에서 작업한 수식 코드가 2015 버전에서는 아래와 같은 빌드 오류가 발생한다.

error c2668 오버 로드 된 함수 에 대한 호출 이 모호 합니다.
error c2668 ambiguous call to overloaded function

MSDN 페이지[각주:1]를 검색 해보니 2015 버전 visual c++ 주요 변경 내용 중에 수식 라이브러리 함수의 C++ 오버로드 함수 관련된 변경사항이 있다.

In previous versions, <math.h> defined some, but not all, of the C++ overloads for the math library functions. <cmath> defined the remaining overloads, so to get all of the overloads, one needed to include the <cmath> header. This led to problems with function overload resolution in code that only included <math.h>. Now, all C++ overloads have been removed from <math.h> and are now present only in <cmath>. To resolve errors, include <cmath> to get the declarations of the functions that were removed from <math.h>.

오류를 해결하려면 <cmath>를 포함하여 <math.h>에서 제거된 함수 선언을 가져와야 합니다. 저의 경우 기존에 작성한 abs(float) 이 2015 버전에서는 위와 같은 이유로 int, long, long long 의 오버로드 함수만 사용 가능했다. 그래서 해결 방법은 두가지 였다. float형 데이터를 int나 long 형으로 캐스팅을 하거나 cmath로 이동한 c++ 오버로드 함수를 사용하기 위해서 #include <cmath> 를 추가하는 방법이었다. 아래 함수들은 cmath로 이동한 함수 리스트 이다.

 

  • double abs(double) 및 float abs(float)
  • double pow(double, int), float pow(float, float), float pow(float, int), long double pow(long double, long double), long double pow(long double, int)
  • 부동 소수점 함수 acos, acosh, asin, asinh, atan, atanh, atan2, cbrt, ceil, copysign, cos, cosh, erf, erfc, exp, exp2, expm1, fabs, fdim, floor, fma, fmax, fmin, fmod, frexp, hypot, ilogb, ldexp, lgamma, llrint, llround, log, log10, log1p, log2, lrint, lround, modf, nearbyint, nextafter, nexttoward, remainder, remquo, rint, round, scalbln, scalbn, sin, sinh, sqrt, tan, tanh, tgamma, trunc의 float 및 long double 버전

 

 

'Coding' 카테고리의 다른 글

Indenting C programs 링크  (0) 2018.04.19
Visual Studio 단축키(Shortcut) 정리 사이트  (0) 2017.01.11
댓글