我有以下代码
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]]
} 在打印时,我得到以下错误:
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)]’如何访问这些州的名称...
发布于 2013-06-18 23:23:57
您可能想要显示P_names[0][...]或类似的内容。你的Node_names是一个定义的,你可能不能像那样使用尖括号。想象一下,如果你删除了你的类型定义,你就必须这样写它:ListDigraph::NodeMap<string>[0][P_names[0]]。这有意义吗?
如果你不提供更多的信息,恐怕我们不能给你更多的帮助。
编辑:尝试使用(*P_names[0])["test"],也许可以做到这一点(假设您拥有所有必要的元素)。
不过,您可以做的一件事是根据需要使用任意多的temp变量。你真的需要了解什么是P_names[0],*P_names[0],(*P_names[0])[...]等类型。试着编译代码,在纸上写类名,看看some diagrams in the documentation,画图(用铅笔在纸上),任何可以帮助你理解上发生的事情。
你正在使用一个不为人所熟知的库,即使这里的人试图帮助你,这也真的很难,特别是没有代码,甚至更糟糕的是,代码不是实际的代码……
https://stackoverflow.com/questions/17172138
复制相似问题