1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
const int Arsize = 10;
template <class Any>
void swap(Any &, Any &);
template <class Any>
void swap(Any*, Any*, int sizer);
template<class Any>
void show(Any*, int sizer);
using namespace std;
int main(void)
{
double first = 3;
double second = 4.6;
cout << "First: " << first << " Second: " << second << "\n";
swap(first, second);
cout << "First: " << first << " Second: " << second << "\n";
int firs[Arsize] = {0,4,1.6,9,1,9,7,6};
int secon[Arsize] = {0,2.4,1,4,2,0,0,1};
show(firs, Arsize);
show(secon, Arsize);
swap(firs, secon, int(Arsize));
show(firs, Arsize);
show(secon, Arsize);
return 0;
}
template <class Any>
void swap(Any&a, Any&b)
{
Any temp = a;
a = b;
b = temp;
}
template <class Any>
void swamp(Any*pa, Any*pb, int sizer)
{
for(int i = 0; i<sizer; i++)
pa[i]=pb[i];
}
template <class Any>
void show(Any*pa, int sizer)
{
cout << pa[0] << pa[1] << "/"
<< pa[2] << pa[3] << "/";
for(int i = 0; i<4; i++)
cout << pa[i];
cout << "\n";
}
|