开发者

Inserting item into map, which holds 2 more map

I am trying to insert an item, into a map, which holds two other map.

map< map<int, int> , map<int, int> > GC;

map<int, int> A;
A.insert(pair<int,int>(1,1));
map<int, int>:: iterator p1 = A.begin();

map<int, int> B;
B.insert(pair<int,int>(2,3));
map<int, int>:: iterator p2 = B.begin();

GC.insert( pair< map<int,int>, map<int,int> > (*p1, *p2) );

Well, as presumed its not working.

How to do it?

EDIT:

It gives the following error:

E:\CB\test.cpp|20|error: no matching function for call to 'std::pair<std::map<int, int, std::less<int>, std::allocator<std::pair<const int, int> > >, std::map<int, int, std::less<int>, std::allocator<std::pair<const int, int> > > >::pair(std::pair<const int, int>&, std::pair<const int, int>&开发者_运维知识库)'


I am not sure what are trying to achieve here .....

Your key and value needs to be an map object in order to work... In that case only possibility is

GC.insert( pair< map<int,int>, map<int,int> > (A,B) );


I think you really want a Node class with a list/vector of Edge objects. Each Edge object would contain the edge weight and a pointer to the Node that edge connected to.

There may be better ways to create a graph than I have described, but this should get you thinking in the right direction.


map<keyValue, VertexIndexValue>, map<(EdgeWeight1,VertexIndexValue1), (EdgeWeight2,VertexIndexValue2)......> 

I think what you want is to use a structure as the second element of your map. It gives you the chance to hold whatever you want in the map without it getting confusing.

struct sMapValue
{
   int mVertIndex;
   map<int, int>  mVertEdgeMap;
};

map< int, sMapValue> GC;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜