//count.h
#ifndefCOUNT_H
#defineCOUNT_H
#includeiostream
#includestring
usingnamespacestd;
templateclassType
intcount(Type*,int,constType
#endif
//count.cpp
#include\"count.h\"
exporttemplateclassType
intcount(Type*a,intsz,constType
for(inti=0;isz;i)
if(a==which)
n;
returnn;
}
//main.cpp
#include\"count.h\"
intmain(){
doublea[]={10.,20.,30.,40.,50.,30.,70.,80.,30.};
cout\"count(a,9,30.)shouldreturn3:\"count(a,9,30.)endl;
intb[]={10,20,30,40,50,30,70,80,30};
cout\"count(b,9,30)shouldreturn3:\"count(b,9,30)endl;
charc[]={\'a\',\'a\',\'c\',\'a\'};
cout\"count(c,4,\'a\')shouldreturn3:\"count(c,4,\'a\')endl;
stringd[]={\"aa\",\"aa\",\"aa\"};
cout\"count(d,3,\\\"aa\\\")shouldreturn3:\"count(d,3,string(\"aa\"))endl;
stringe[]={\"bb\",\"aa\",\"aa\"};
cout\"count(e,3,\\\"aa\\\")shouldreturn2:\"count(e,3,string(\"aa\"))endl;
return0;
}
麻烦哪位大虾指点指点哪里错了啊?
|