template 다다시

YP J·2022년 9월 29일
0

ft_container

목록 보기
7/8

https://wikidocs.net/408
#include

template <typename T, typename U>
T  max(T const &a, U const &b)
{
	return a < b ? b: a;
}

int main()
{
	std::cout << max<float,int>(100.1,100) << std::endl;

	std::cout << max<int,float>(100,20.f) << std::endl;
	std::cout << max<double,int>(100.1,20) << std::endl;
}
  • 근데 이러면 return 되는 값이 항상 앞에 있는 인자 T 부분 이다
  • 예를 들면 max<int,float>(100,100.1f) 이면 100.1 이 리턴 되지만 T형식을 리턴 하기 때문에 100 으로 리턴 된다.
  • 이문제 해결을 위해 어떻게..?
profile
be pro

0개의 댓글