[問題] C++ std:set用find的問題

看板C_and_CPP (C/C++)作者 (baseball boy)時間15年前 (2011/01/16 19:28), 編輯推噓3(307)
留言10則, 2人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) codebolcks c++ 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): for(set<Node*>::iterator it = B.dom.begin(); it != B.dom.end(); ++it) { for(set<Node*>::iterator i = C.dom.begin(); i != C.dom.end(); ++i) { z.dom.insert(&(*it).find(&(*i))); } } 想讓z.dom.insert(&(*it).find(&(*i))); 這一行正常執行 餵入的資料(Input): 預期的正確結果(Expected Output): 讓z.dom.insert(&(*it).find(&(*i))); 這一行正常執行 錯誤結果(Wrong Output): error: request for member 'find' in 'it.std::_Rb_tree_const_iterator<_Tp>::operator* [with _Tp = Node*]()', which is of non-class type 'Node* const' 程式碼(Code):(請善用置底文網頁, 記得排版) #include <set> #include <string> #include <stdio.h> using namespace std; class Node; /////////////SET compare全部設定為true////// struct NodeCompare { bool operator() (const Node& left, const Node& right) const { return true; } }; class Node { public: Node(){}; virtual ~Node(){}; void printDebug(){printf("%s\n", name.c_str());}; set<Node*> idom; set<Node*> dom; }; int main(){ Node A, B, C, D, z; B.dom.insert(&S); C.dom.insert(&A); C.dom.insert(&S); for(set<Node*>::iterator it = B.dom.begin(); it != B.dom.end(); ++it) { for(set<Node*>::iterator i = C.dom.begin(); i != C.dom.end(); ++i) { z.dom.insert(&(*it).find(&(*i))); } } 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.250.8.138

01/16 19:32, , 1F
01/16 19:32, 1F

01/16 21:45, , 2F
z.dom.insert(*((*it)->dom.find(*i))); //這樣?
01/16 21:45, 2F

01/16 22:24, , 3F
K大 這樣的方法可以耶 謝謝你
01/16 22:24, 3F

01/16 22:25, , 4F
現在想改成z.dom.insert(B.dom->dom.find(*i));卻不行.
01/16 22:25, 4F

01/16 22:33, , 5F
z.dom.insert(*(B.dom->dom.find(*i)));
01/16 22:33, 5F

01/16 22:34, , 6F
find回傳的是iterator 加*變Node*
01/16 22:34, 6F

01/16 22:43, , 7F
有錯說 has non-pointer type 'std::set<Node*,
01/16 22:43, 7F

01/16 22:44, , 8F
std::less<Node*>, std::allocator<Node*> >
01/16 22:44, 8F

01/16 22:46, , 9F
z.dom.insert(*(B.dom.find(*i)));
01/16 22:46, 9F

01/16 22:51, , 10F
他動了..我太感動了 謝謝你
01/16 22:51, 10F
文章代碼(AID): #1DCjPfwG (C_and_CPP)
文章代碼(AID): #1DCjPfwG (C_and_CPP)