这个程序怎么改呀?
#include <iostream>using namespace std;
template <typename Type,int size>
void count(Type (&r_array)[size], Type value)
{
int cnt = 0;
for(int ix=0;ix<size;++ix)
{
if(value == r_array[ix])
++cnt;
}
cout << value << "出现次数为" << cnt << endl;
}
template <> void count<char>(char (&ch_array)[size], char ch)
{
int cnt = 0;
for(int ix=0;ix<size;++ix)
{
if(ch == ch_array[ix])
++cnt;
}
cout << ch << "出现的次数为" << cnt << endl;
}
int main()
{
int a[] = {34,56,12,31,12,34,12,34,12};
double b[] = {24.0,34.3,24.0,12.3,34.1,24.0};
char ch[] = "hello songhuirong.";
count(a,12);
count(b,24.0);
count(ch,'o');
return 0;
}
这是一个模板特化实例的程序,但是编译报错,改怎么改呢?说size是未声明的标识符。