C++编译报错:need ‘typename’ before ‘std::map::iterator’

使用C++的模板函数做展示输出

template <typename T>
    inline void displayVector(vector<T>& vec){
    	for(T v : vec)cout << v;
    	cout << endl;
	}
	
	template <typename T, typename S>
	inline void displayMap(map<T, S>& mp){
		for(typename map<T, S>::iterator iter = mp.begin(); iter!=mp.end(); iter++)cout << iter->first << " " << iter->second << endl;
	}
	
	template <typename T, typename S>
	inline void displayMapVector(map<T, vector<S>>& mp){
		for(typename map<T, vector<S>>::iterator iter = mp.begin(); iter != mp.end(); iter++)cout << iter->first << " " << displayVector(iter->second);
	}

报错后在map::iterator前面加个typename声明模板类型是类型名即可。
参考链接:
Error: need ‘typename’ before iterator [duplicate]
编译错误need 'typename' before *** because *** is a dependent scope 浅析

原文链接: https://www.cnblogs.com/tellw/p/13908324.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    C++编译报错:need 'typename' before 'std::map<T, S>::iterator'

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/204624

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月12日 下午9:55
下一篇 2023年2月12日 下午9:56

相关推荐