我可能做錯了什麼。有人能向我解釋究竟是什麼?C++ 11 lambda函數將不接受類方法
某處類SemanticNodeFactory,我有:
std::pair<C_ptr,R_ptr> Find(Token token )
{
C_ptr concept = nullptr;
R_ptr relation = nullptr;
//concept = concept_map->Find(token); <- This works
//relation = relation_map->Find(token); <- And this too
std::thread t1 ([&concept,this] (Token token) { concept = concept_map->Find(token); });
std::thread t2 ([&relation,this] (Token token) { relation = relation_map->Find(token); });
被調用時的實際方法屬於:
typedef std::shared_ptr<Relation> R_ptr;
typedef std::shared_ptr<Concept> C_ptr;
std::shared_ptr<SemanticGraph<Relation>> relation_map;
std::shared_ptr<SemanticGraph<Concept>> concept_map;
然而,編譯器會抱怨說:
error: no match for call to ‘(SemanticNodeFactory::Find(Token)::<lambda(Token)>)()’
note: candidate is:
note: SemanticNodeFactory::Find(Token)::<lambda(Token)>
然而,我試圖調用的實際方法實際上是:
SemanticGraph<Relation>::Find(Token)
SemanticGraph<Concept>::Find(Token)
我在做什麼錯? 我通過引用捕獲這個局部變量,但它似乎抱怨實際的方法?
謝謝,就是這樣,我甚至沒有注意線程值... –