访问Lemon Graph Library中的向量中的映射值

时间:2013-06-18 14:54:59

标签: c++ lemon-graph-library

我有以下代码

typedef ListDigraph::NodeMap<string> Node_names;
vector<ListDigraph::Node> initial_state;
vector<Node_names*> P_names;
//some loop
{
   Node_names name;
   ListDigraph::Node state = graph.addNode();
   initial_state = state;
   name[state] = "state1";
   P_names.push_back(&name);
}

void printin()
{
    cout<<P_names[0][initial_state[0]]
} 

在printin中我收到错误:

error: no match for ‘operator[]’ in ‘((Translator*)this)->Translator::Process_state_name.std::vector<_Tp, _Alloc>::operator[] [with _Tp = lemon::DigraphExtender<lemon::ListDigraphBase>::NodeMap<std::basic_string<char> >*, _Alloc = std::allocator<lemon::DigraphExtender<lemon::ListDigraphBase>::NodeMap<std::basic_string<char> >*>, std::vector<_Tp, _Alloc>::reference = lemon::DigraphExtender<lemon::ListDigraphBase>::NodeMap<std::basic_string<char> >*&, std::vector<_Tp, _Alloc>::size_type = unsigned int](0u)[((Translator*)this)->Translator::Process_initial_state.std::vector<_Tp, _Alloc>::operator[] [with _Tp = lemon::ListDigraphBase::Node, _Alloc = std::allocator<lemon::ListDigraphBase::Node>, std::vector<_Tp, _Alloc>::reference = lemon::ListDigraphBase::Node&, std::vector<_Tp, _Alloc>::size_type = unsigned int](0u)]’

我如何访问州的名称....

1 个答案:

答案 0 :(得分:1)

您可能希望显示P_names[0][...]或类似的内容。您的Node_names定义,您可能无法使用这样的尖括号。可以想象,如果你删除了你的typedef,就必须这样写:ListDigraph::NodeMap<string>[0][P_names[0]]。那会有意义吗?

如果您不提供更多信息,我们无法帮助您更多...

编辑:尝试(*P_names[0])["test"],也许会这样做(假设您拥有所有必要的元素)。

您可以做的一件事是使用尽可能多的临时变量。你真的需要了解P_names[0]*P_names[0](*P_names[0])[...]等类型。尝试编译代码,在纸上写类名,看看some diagrams in the documentation,绘制图表(用铅笔在纸上),任何可以帮助您了解正在发生的事情

你正在使用一个众所周知的图书馆,即使这里的人们试图帮助你,也很难,特别是没有代码,甚至更糟糕的是代码不是真正的代码......

相关问题