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

以上怎么写个函数模板 的函数

2013-01-06 
以下如何写个函数模板 的函数?typedef multimapint,int ClientIndextypedef multimapint,string Form

以下如何写个函数模板 的函数?



typedef multimap<int,int> ClientIndex;
typedef multimap<int,string> FormIndex;
void __fastcall FindValue( ClientIndex* map,int key,int value)
{
ClientIndex::size_type count = map->count(key);
if(count > 0)
{
ClientIndex::iterator iter = map->find(key);
for(ClientIndex::size_type  cnt = 0; cnt!= count; ++cnt,++iter)
{
if(iter->second  == value)
{
   //如果在multimap中找到value相同的就退出
   return;
}
}
//如果没有找到对应的value,就插入到multimap中
}
//没有找到对应的key 值,或者value值就插入到multimap中
map->insert(make_pair(key,value));
}
void __fastcall FindValue(FormIndex* map,int key ,const string &value)
{
FormIndex::size_type count = map->count(key);
if(count > 0)
{
FormIndex::iterator iter = map->find(key);
for(FormIndex::size_type  cnt = 0; cnt!= count; ++cnt,++iter)
{
string tempvalue = iter->second;
if(tempvalue == value)
{
   //如果在multimap中找到value相同的就退出
   return;
}
}
//如果没有找到对应的value,就插入到multimap中
}
//没有找到对应的key 值,或者value值就插入到multimap中
map->insert(make_pair(key,value));
}
template <class T,class I>
void __fastcall FindValue(T* map,int key ,I value)
{
 //这个该如何实现
}

上述函数主要在multimap中实现查找对应的key,和value
[解决办法]
引用:
引用:C/C++ code?1234567891011121314151617181920212223template <class T>void __fastcall FindValue(multimap<int,T>* map,int key ,const T &amp;amp;value){    typedef multimap<……
string是可以直接用==比较的,你再去好好看一看

热点排行