Skip to content

Commit

Permalink
function template
Browse files Browse the repository at this point in the history
This program is used to learn the function template
  • Loading branch information
feihun1 committed Apr 1, 2017
1 parent b18bfe0 commit 756395f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions cpp six.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//A function template(can overloading)
#include <iostream>
using namespace std;
template <typename T>
void Swap(T &a, T &b);
template <typename T>
void Swap(T &a, T &b)
{
T temp;
temp = a;
a = b;
b = temp;
}
int main()
{
int i = 10,j=20;
cout << "i,j=" << i << "," << j << endl;
Swap(i, j);
cout << "using compiler-generated int swapper:" << endl;
cout << "Now i,j=" << i << "," << j << endl;
double x = 24.5;
double y = 81.7;
cout << "x,y=" << x << "," << y << endl;
Swap(x, y);
cout << "using compiler-generated double swapper:"<<endl;
cout << "Now x,y=" << x << "," << y << endl;
cin.get();
return 0;
}

0 comments on commit 756395f

Please sign in to comment.