关于linux与windows stl map的问题

devilbelief 2009-09-21 04:56:55
#include <map>
using namespace std;

template<typename K, typename T>
class a
{
public:
map<K,T> _map;
T find(K v)
{
map<K,T>::iterator iter;
iter = _map.find(v);
if(iter != _map.end())
return iter->second;
else
return (T)0;
}
};
int main()
{
a<int, unsigned int> b;
return 0;
}

为什么这段代码在vc2005中可以编译通过,而在linux(red heat)下不能通过?
...全文
158 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
devilbelief 2009-09-21
  • 打赏
  • 举报
回复
受教了,看来得好好学习了!
mstlq 2009-09-21
  • 打赏
  • 举报
回复

#include <map>
using namespace std;

template<typename K, typename T>
class a
{
public:
map<K,T> _map;
T find(K v)
{
typename map<K,T>::iterator iter;//mark
iter = _map.find(v);
if(iter != _map.end())
return iter->second;
else
return (T)0;
}
};
int main()
{
a<int, unsigned int> b;
return 0;
}
yutaooo 2009-09-21
  • 打赏
  • 举报
回复

加上 typename.
如下:

#include <map>
using namespace std;

template<typename K, typename T>
class a
{
public:
map<K,T> _map;
T find(K v)
{
typename map<K,T>::iterator iter;
iter = _map.find(v);
if(iter != _map.end())
return iter->second;
else
return (T)0;
}
};

int main()
{
a<int, unsigned int> b;
return 0;
}
taodm 2009-09-21
  • 打赏
  • 举报
回复
呃,google 模板参数依赖类型。
typename的功能没好好学吧。
devilbelief 2009-09-21
  • 打赏
  • 举报
回复
test.cpp: In member function `T a<K, T>::find(K)':
test.cpp:11: error: expected `;' before "iter"
test.cpp:12: error: `iter' was not declared in this scope

red heat下编译报这个错
devilbelief 2009-09-21
  • 打赏
  • 举报
回复
去掉a<int, unsigned int> b;这行也一样,与模板参数无关
老邓 2009-09-21
  • 打赏
  • 举报
回复
那是因为int和unsigned int在linux平台下没有区别。
模板的二义性。与编译器实现有关。
Title: The core of the big data solutions -- Map. Author: pengwenwei address: No.17-18 of XiangGangbatang Community, Xiangtan City of Hunan Province, China. Language: c++ Platform: Windows, linux Technology: Perfect hash algorithm Level: Advanced Description: A high performance map algorithm Section MFC c++ map stl SubSection c++ algorithm License: (GPLv3) Map is widely used in c++ programs. Its performance is critical to programs' performance. Especially in big data and the scenarios which can't realize data distribution and parallel processing. I have been working on big data analysis for many years in telecommunition and information security industry. The data analysis is so complicated that they can't work without map. Especially in information security industry, the data is much more complicated than others. For example, ip table, mac table, telephone numbers table, dns table etc. Currently, the STL map and Google's hash map are the most popular maps. But they have some disadvantages. The STL map is based on binary chop, which causes a bad performance. Google Hash map has the best performance at present, but it has probability of collision. For big data analysis, the collision probability is unacceptable. Now I would like to publish pwwMap. It includes three different maps for different scenarios: 1. Memory Map(memMap): It has a good access speed. But its size is limited by memory size. 2. Harddisk Map(diskMap): It utilizes hard disk to store data. So it could accept much more data than memory map. 3. Hashmap(hashMap): It has the best performance and a great lookup speed, but it doesn't have 'insert' and 'delete' functionality. MemMap and diskMap could be converted to hashMap by function memMap2HashMap and diskMap2HashMap. According to the test result, my algorithms' collision probability is zero. About performance, memMap has a comparable performance with google, and hashMap's performance is 100 times better than Google's hashmap. In summary, pwwhash are perfect hash algorithms with zero collision probability. You can refer to following artical to find the key index and compress algorithm theory: http://blog.csdn.net/chixinmuzi/article/details/1727195 Source code and documents: https://sourceforge.net/projects/pwwhashmap/files/?source=navbar

64,645

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧