模板具体化

#ifndef SWAP_H_INCLUDED
#define SWAP_H_INCLUDED
#include <iostream>
using namespace std;
struct Job
{
    string name;
    int salary;
};

template <typename T>
void Swap(T &a, T &b);

template <>
void Swap<Job>(Job &, Job &);

template <typename T>
void Swap(T &a, T &b)
{
    T tmp = a;
    a = b;
    b = tmp;
}


template <>
void Swap<Job>(Job &a, Job &b)
{
    int tmp;
    tmp = a.salary;
    a.salary = b.salary;
    b.salary = tmp;
}

#endif // SWAP_H_INCLUDED

  

posted on 2014-05-15 15:23  jesse_deng  阅读(316)  评论(0编辑  收藏  举报

导航