功能模板可以使用地图参数吗?

时间:2015-05-29 01:17:26

标签: function templates dictionary parameters

我有一组这样的数据类型:

map<Type, SubComponent*>.

我想对他们做类似的操作,所以我想考虑使用这样的功能模板:

template< typename Type, typename SubComponent >
void DeleteSubComponents( map<Type, SubComponent*> &subComponentMap )
{
    for( map<Type, SubComponent*>::iterator it=subComponentMap.begin();
         it!=subComponentMap.end(); ++it ){
        if( NULL != it->second ){
            delete it->second;
            it->second = NULL;
        }
    }
    subComponentMap.clear();

    return;
}

但它没有错误编译:

line 967:  error: dependent-name ‘std::map<Type,SubComponent*,std::less<_Key>,std::allocator<std::pair<const Type, SubComponent*> > >::iterator’ is parsed as a non-type, but instantiation yields a type
line 967: note: say ‘typename std::map<Type,SubComponent*,std::less<_Key>,std::allocator<std::pair<const Type, SubComponent*> > >::iterator’ if a type is meant

我对此一无所知,功能模板可以使用地图参数吗?谢谢!

0 个答案:

没有答案