[英]Accessing map values in a vector in 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)]’
我如何訪問各州的名稱...
您可能要顯示P_names[0][...]
或類似的內容。 您的Node_names
是一個define ,您可能不能使用這樣的尖括號。 就像刪除了typedef一樣,就必須這樣寫: ListDigraph::NodeMap<string>[0][P_names[0]]
。 那有意義嗎?
如果您不提供更多信息,恐怕我們真的不能為您提供更多幫助...
編輯:試試(*P_names[0])["test"]
,也許可以做到這一點(前提是您擁有所有必要的元素)。
不過,您可以做的一件事就是使用所需的多個臨時變量。 您確實需要了解什么類型是P_names[0]
, *P_names[0]
, (*P_names[0])[...]
等。嘗試編譯代碼,在紙上寫類名,看看文檔中的某些圖表 ,繪制的圖表(用鉛筆在紙上)或任何可以幫助您了解發生了什么的內容 。
您正在使用一個鮮為人知的庫,即使這里的人試圖幫助您,也確實很難,尤其是沒有代碼,或者甚至是使用不是實際代碼的代碼更糟...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.