递归STL映射
我正在尝试制作一棵地图树(或者只是将一个地图的值指向另一个地图),但我不太确定如何解决这个问题。我找到了关于此的讨论: http://bytes.com /topic/c/answers/131310-how-build-recursive-map 但我对那里发生的事情有点困惑。
例如,我的键是一个字符,我的值是下一个地图。这是假设的声明:
map< char, map< char, map< char.......>>>>>>>>>> root_map;
I'm trying to make a tree of maps (or just have values of a map point to another map), but I'm not too sure how to approach this. I found a discussion about this: http://bytes.com/topic/c/answers/131310-how-build-recursive-map but I'm a little confused on what's going on there.
For example, my key is a char, and my value is the next map. Here's the hypothetical declaration:
map< char, map< char, map< char.......>>>>>>>>>> root_map;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
也许您正在想这样的事情:
我真的不会推荐它。
Maybe you're thinking of something like:
I wouldn't really recommend it.
我不太确定你想要实现什么,但是当我听到“地图树”时,我想到了以下内容:
I'm not excatly sure what you want to achieve, but when I hear "tree of maps" I think of the following:
作为想法,像这样:
并像这样使用它
也许您可以通过 CharMap 上的附加方法和运算符使其更加奇特,这将在访问您的结构时消除 .map 的需要。
As idea, something like this:
and use it like
Probably you could make it more fancy with additional methods and operators on the CharMap that would eleminate the need of the .map when accessing your structure.
是的,你可以。为了让地图做任何有用的事情,您必须使用方法(在本例中为 Set 和 Get)来装饰它。
Yes you can. In order for the map to do anything useful though, you're going to have to decorate it with methods (in this case, Set and Get).