[問題] compile error

看板EE_DSnP作者 (meanid)時間14年前 (2011/12/21 21:03), 編輯推噓4(401)
留言5則, 2人參與, 最新討論串6/6 (看更多)
有幾個看不懂的error麻煩強者帮我解答一下... 第一個: cirMgr.cpp:234: error: ‘class __gnu_cxx::__normal_iterator<CirPiGate**, std::vector<CirPiGate*, std::allocator<CirPiGate*> > >’ has no member named ‘ getId’ code: vector<CirPiGate*>::iterator its; its = _pi.begin(); for(; its< _pi.end(); its++) if(its.getId() == id) . . . _pi是一個我用來存CirPiGate*的vector CirPiGate 是一個計承 CirGate 的 class 以上四行code是在一個switch case裡面的 我檢查過了裡面有getId 這個 member function(在CirGate裡面,非virtual) 第二個: cirMgr.cpp:303: error: switch quantity not an integer code: switch(ilo.c_str()){ . . . ilo是一個只有一個字的string 想把它轉成char來判斷 不知道這樣轉可不可以?? 麻煩各位了QQ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.25.108

12/21 21:14, , 1F
(*its).getId()
12/21 21:14, 1F

12/21 21:15, , 2F
or (*its)->getId()? since the data in vector is an ptr
12/21 21:15, 2F

12/21 21:17, , 3F
switch can only accept "int", and x.c_str() is char*
12/21 21:17, 3F

12/21 21:18, , 4F
I think you should use "ilo[0]"
12/21 21:18, 4F

12/21 21:37, , 5F
got it!! thx!!
12/21 21:37, 5F
文章代碼(AID): #1EyTai_K (EE_DSnP)
文章代碼(AID): #1EyTai_K (EE_DSnP)