c++primer plus第六版中文版程序清单8.13遇到的一些问题
#include "stdafx.h"#include<iostream>
template<typename t>
void swap(t &a,t & b);
struct job
{
char name[40];
double salary;
int floor;
};
template<> void swap <job>( job &j1 ,job &j2 );
void show(job &j);
using namespace std;
int main()
{
cout.precision (2);
cout.setf (ios_base ::fixed ,ios_base ::floatfield );
int i=10,j=20;
cout<<"i,j= "<<i<<" : "<<j <<endl ;
cout<<" using compilar—generated swap.\n";
swap (i,j);
cout<<"now,i,j= "<<i<<" : "<<j<<endl ;
job sue={"susan",7300.60,7};
job sidney={" sidney teffee",78060.72,9,};
cout<<"before job swaping:\n";
show(sue );
show(sidney );
cout<<"after job swaping :\n";
swap (sue,sidney);
show(sue );
show(sidney );
return 0;
}
template<typename t>
void swap(t &a,t&b)
{
t temp;
temp =a;
a=b;
b=temp
}
template<> void swap <job>( job &j1 ,job &j2 )
{
double t1;
int t2;
t1=j1.salary ;
t2 =j1.floor ;
j1 .salary=j2 .salary ;
j1 .floor =j2 .floor ;
j2 .salary=t1;
j2 .floor=t2;
}
void show (job &j)
{
cout<<j.name<<" :$ "<<j.salary<<
" ,on floor "<<j.floor <<endl ;
}
无法调用swap函数,每次都显示实参与形参列表不匹配;或对重载函数的调用不明确。
是我哪里错了吗,我用是vs2012