开发者

How to declare boost unordered_multimap

I'm trying to use the boost unordered_multimap class and I'm having trouble declaring it. The error follows the code.

#include <iostream>
#include <map> // header file needed for to use MAP STL
#include <boost/unordered_map.hpp>

using namespace std;

int main(void)
{

map<int, map<int, map<int,int> > > _3dstl;

_3dstl[0][0][0] = 10;

cout<<_3d[0][0][0]<<endl;


typedef boost::unordered_multimap<int, typedef boost::unordered_multimap<int, int>> unordered_map;
unordered_map _2d;

    return 0;
}

This is the error:

||In function 'int main()':|
|17|error: template argument 2 is invalid|
|17|error: template argument 5 is in开发者_开发知识库valid|
|17|warning: 'typedef' was ignored in this declaration|
|18|error: 'unordered_map' was not declared in this scope|
|18|error: expected ';' before 'location3d'|
||=== Build finished: 4 errors, 1 warnings ===|


Change this line:

typedef boost::unordered_multimap<int, typedef boost::unordered_multimap<int, int>> unordered_map;

To this:

typedef boost::unordered_multimap<int, boost::unordered_multimap<int, int> > unordered_map;

The second typedef is not necessary and a syntax error. Also in C++2003 you have to watch out for >> in template declarations.


Also, please use a different name then unordered_map for the typedef, since this will collide with std::unordered_map if you use using namespace std; (which is IMO a bad practice). A suggestion would be intmap2d or something.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜