C++模版特化问题(拜托了)
程序不能执行,编译器是 dev
#include <string>using namespace std;template <typename Type> int count(Type *a, int sz, Type which ){ int n = 0; for(int i=0; i < sz; i++) if ( a[i] == which ) n++; return n;}#include <iostream>#include <stdlib.h>#include <string>#include "count.h"using namespace std;//模版特化,却不能执行 ???? //template int count< string >(string* ,int ,string );//即时此处加上模版定义仍然不能执行int main(){ int a[10] = {1,5,6,9,2,123,5,78,54,5}; double b[6] = {1.0,2.0,3.0,2.0,6.0,2.0}; string s[6] = {"aa","bb","aa","cc","dd","aa",}; cout << "the number of 5 is: " << count(a,10,5) << endl; cout << "the number of 2.0 is: " << count(b,6,2.0) <<endl; // cout << "the number of string \"aa\" is: " << count(s,6,"aa") << endl; system("pause"); return 0;}#include <iostream>using namespace std;#include <string>template <typename Type> int count(Type *a, int sz, Type which ){ int n = 0; for(int i=0; i < sz; i++) if ( a[i] == which ) n++; return n;}//模版特化,却不能执行 ???? template int count< string >(string* ,int ,string );//即时此处加上模版定义仍然不能执行int main(){ int a[10] = {1,5,6,9,2,123,5,78,54,5}; double b[6] = {1.0,2.0,3.0,2.0,6.0,2.0}; string s[6] = {"aa","bb","aa","cc","dd","aa",}; cout << "the number of 5 is: " << count(a,10,5) << endl; cout << "the number of 2.0 is: " << count(b,6,2.0) <<endl; // cout << "the number of string \"aa\" is: " << count(s,6,"aa") << endl; system("pause"); return 0;}
[解决办法]
有什么编译器支持分离编译模式啊???
现在的编译器都不支持