[問題] C++ std:set用find的問題
看板C_and_CPP (C/C++)作者alex200222 (baseball boy)時間15年前 (2011/01/16 19:28)推噓3(3推 0噓 7→)留言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
01/16 21:45, 2F
→
01/16 22:24, , 3F
01/16 22:24, 3F
→
01/16 22:25, , 4F
01/16 22:25, 4F
推
01/16 22:33, , 5F
01/16 22:33, 5F
→
01/16 22:34, , 6F
01/16 22:34, 6F
→
01/16 22:43, , 7F
01/16 22:43, 7F
→
01/16 22:44, , 8F
01/16 22:44, 8F
推
01/16 22:46, , 9F
01/16 22:46, 9F
→
01/16 22:51, , 10F
01/16 22:51, 10F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章