개요 ¶
복습 ì°¨ì›�ì—�서 템플릿ì�„ ê³µë¶€í•˜ê³ ì—°ìŠµí•˜ì˜€ë‹¤.
소스 ¶
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
template <typename T>
T multiply(T a, T b) {
return a*b;
}
template <typename U>
U subtract(U a, U b) {
return a-b;
}
int main(void) {
cout<<multiply(4,5)<<endl;
cout<<multiply(subtract(5,3),subtract(3,5))<<endl;
return 0;
}
Output ¶
20
-4
-4
후기 ¶
템플릿 함수를 ì„ ì–¸í• ë•Œ, ì„ ì–¸ë¶€ì™€ ì •ì�˜ë¶€ë¥¼ 분리하면 ì—�러가 나는ë�° 왜 그런지 ëª¨ë¥´ê² ë‹¤.










