-
#include <bits/stdc++.h>
using namespace std;template <class A, class B>
auto funmin(A a, B b) -> decltype(a < b ? a : b)
{
return a < b ? a : b;
}int main()
{
cout << funmin(4,3.44) << endl;
cout << typeid(funmin(4,3.44)).name() << endl;cout << funmin(5.4, 3) << endl;
cout << typeid(funmin(5.4, 3)).name() << endl;cout << funmin(5, 3) << endl; // No err mssg, but wrong
cout << typeid(funmin(5, 3)).name() << endl; //cout << funmin(5.1, 3.2) << endl; //No err mssg, but wrong
cout << typeid(funmin(5.1, 3.2)).name() << endl;return 0;
}아웃풋: (컴파일러마다 조금 다를수는 있음.)
3.44
d
3
d
0
i
0
dfunmin(a,b) 는 두 수중 작은 수를 리턴하는 간단한 함수.
아웃풋이 보다시피, 같은 정수끼리나 같은 더블타입의 숫자끼리는 틀린 결과를 출력함. 이유가 뭘까? 뭐가 잘못되었는지 밝혀내는게 퀴즈. 쉬운 난이도는 아니므로 실력있는 사람만 도전할것.
힌트 :decltype()