NDK开发中使用stl中的hash_map

呀呀的呀 2012-08-28 12:11:54

#include <hash_map>

namespace stdext
{
template<> size_t hash_compare< std::string, std::less< std::string > >::operator ()( const std::string& _stringBase ) const
{
register size_t ret = 0;
for( std::string::const_iterator it = _stringBase.begin(); it != _stringBase.end(); ++it )
ret = 5 * ret + *it;
return ret;
}
}

typedef stdext::hash_compare< string, std::less< string > > StringHash;




不知以上写法是否哪里错误了,我在eclipse中编译总是会报错:
error: expected initializer before '<' token
...全文
402 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
呀呀的呀 2012-09-06
  • 打赏
  • 举报
回复
结贴结贴咯
呀呀的呀 2012-08-30
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

引用 4 楼 的回复:

引用 2 楼 的回复:

C/C++ code

#include <hash_map>

namespace stdext
{
template<> size_t hash_compare< std::string, std::less< std::string > >::operator ()( const std::string&a……
[/Quote]

对的,vs上是没有问题的,因为他又hash_compare这个模板类,但是NDK中貌似没有了
呀呀的呀 2012-08-30
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]

引用 5 楼 的回复:

引用 1 楼 的回复:

hash_compare 是类模板吗?如果是的话,必须先特化类模板本身,然后在特化其成员函数。如果不是的话,hash_compare :: operator () 的写法就是错误的。


我查看了一下,在vs下找到该文件,是模板类,不知是否是因为我做android NDK开发,标准stl无该文件,我搜索了下,找不到该文件

……
[/Quote]

恩,感谢,我在试试看
呀呀的呀 2012-08-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

hash_compare 是类模板吗?如果是的话,必须先特化类模板本身,然后在特化其成员函数。如果不是的话,hash_compare :: operator () 的写法就是错误的。
[/Quote]

我查看了一下,在vs下找到该文件,是模板类,不知是否是因为我做android NDK开发,标准stl无该文件,我搜索了下,找不到该文件
呀呀的呀 2012-08-28
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

C/C++ code

#include <hash_map>

namespace stdext
{
template<> size_t hash_compare< std::string, std::less< std::string > >::operator ()( const std::string& _stringBase ) const
{
……
[/Quote]

??不是跟我的代码一样吗
呀呀的呀 2012-08-28
  • 打赏
  • 举报
回复
[Quote=引用楼主 的回复:]
C/C++ code

#include <hash_map>

namespace stdext
{
template<> size_t hash_compare< std::string, std::less< std::string > >::operator ()( const std::string& _stringBase ) const
{
……
[/Quote]

我查看了一下,在vs下找到该文件,是模板类,不知是否是因为我做android NDK开发,标准stl无该文件,我搜索了下,找不到该文件
xcyl 2012-08-28
  • 打赏
  • 举报
回复

#include <hash_map>

namespace stdext
{
template<> size_t hash_compare< std::string, std::less< std::string > >::operator ()( const std::string& _stringBase ) const
{
register size_t ret = 0;
for( std::string::const_iterator it = _stringBase.begin(); it != _stringBase.end(); ++it )
ret = 5 * ret + *it;
return ret;
}
}

typedef stdext::hash_compare< std::string, std::less< std::string > > StringHash;

ri_aje 2012-08-28
  • 打赏
  • 举报
回复
hash_compare 是类模板吗?如果是的话,必须先特化类模板本身,然后在特化其成员函数。如果不是的话,hash_compare :: operator () 的写法就是错误的。
xcyl 2012-08-28
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

引用 2 楼 的回复:

C/C++ code

#include <hash_map>

namespace stdext
{
template<> size_t hash_compare< std::string, std::less< std::string > >::operator ()( const std::string&amp; _stringBase ……
[/Quote]
加了std::string 没搞过NDK不清楚对不对,vs上ok
ri_aje 2012-08-28
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]

引用 1 楼 的回复:

hash_compare 是类模板吗?如果是的话,必须先特化类模板本身,然后在特化其成员函数。如果不是的话,hash_compare :: operator () 的写法就是错误的。


我查看了一下,在vs下找到该文件,是模板类,不知是否是因为我做android NDK开发,标准stl无该文件,我搜索了下,找不到该文件
[/Quote]
hash_map 不是 stl 的一部分。c++03 stl 中没有 hash map,tr1 以后增加了,但是不属于 stl,而属于 stl::tr1,很多编译器也给出了扩展,不过都是非标准的,各家有各家的实现。c++11 统一了 hash map 的要求,为了避免与以前冲突,现行标准的 hash map 叫 std::unordered_map。我猜 vs 比较强大,有提供非标准扩展 hash_map,NDK 功能差,所以没有。



64,646

社区成员

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

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