模板具体化

#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

  

原文地址:https://www.cnblogs.com/jesse-deng/p/3730075.html