首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

C++模版特化有关问题(拜托了)

2012-10-10 
C++模版特化问题(拜托了)程序不能执行,编译器是 devC/C++ code#include stringusing namespace stdtemp

C++模版特化问题(拜托了)
程序不能执行,编译器是 dev


C/C++ code
#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;}


C/C++ code
#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;}


有什么编译器支持分离编译模式啊??? 拜托高手了!!!

[解决办法]
C/C++ code
#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;}
[解决办法]
有什么编译器支持分离编译模式啊???
现在的编译器都不支持

热点排行