Computer/C++&MFC
간단한 템플릿 함수 예제
Y.Hyun
2008. 12. 9. 09:30
#include <stdio.h>
template <typename Type>
void Swap(Type& one, Type& another);
int main()
{
template <typename Type>
void Swap(Type& one, Type& another);
int main()
{
int N = 5, M = 10;
Swap(N, M);
printf("N = %d, M = %d\n", N, M);
double dN = 5.0, dM = 10.0;
Swap(dN, dM);
printf("dN = %f, dM = %f\n", dN, dM);
return 0;
Swap(N, M);
printf("N = %d, M = %d\n", N, M);
double dN = 5.0, dM = 10.0;
Swap(dN, dM);
printf("dN = %f, dM = %f\n", dN, dM);
return 0;
}
template <typename Type>
void Swap( Type&, one, Type& another)
{
template <typename Type>
void Swap( Type&, one, Type& another)
{
Type temp;
temp = one;
one = another;
another = temp;
temp = one;
one = another;
another = temp;
}