簡體   English   中英

錯誤:沒有匹配的函數調用&#39;std :: map <std::__cxx11::basic_string<char>

[英]error: no matching function for call to ‘std::map<std::__cxx11::basic_string<char>

我正在嘗試刪除一般有向加權圖的節點。 刪除節點時,我還需要刪除該節點的入站和出站邊緣,因此,我不僅要刪除該節點,還必須刪除附加到用於鏈接到該節點的其他節點的邊緣。被刪除。

對於該函數,我正在嘗試使用find()函數查找鏈接節點,該函數用於在nodes_內查找一個節點,該節點聲明為:

std::map< N, std::shared_ptr<Node> > nodes_;

我試過originNodeOfIncomingEdge-> edges_.erase(edge); 但它不起作用,因此我嘗試執行以下操作以在執行擦除之前在nodes_的地圖上找到該節點。

auto findLinkingNode1 = nodes_.find(originNodeOfIncomingEdge);

但是,我不斷收到以下錯誤,不確定是什么錯誤。

tests/Graph.tem:558:64: error: no matching function for call to ‘std::map<std::__cxx11::basic_string<char>, std::shared_ptr<gdwg::Graph<std::__cxx11::basic_string<char>, int>::Node>, std::less<std::__cxx11::basic_string<char> >, std::allocator<std::pair<const std::__cxx11::basic_string<char>, std::shared_ptr<gdwg::Graph<std::__cxx11::basic_string<char>, int>::Node> > > >::find(std::shared_ptr<gdwg::Graph<std::__cxx11::basic_string<char>, int>::Node>&)’
    auto findLinkingNode1 = nodes_.find(originNodeOfIncomingEdge);
                                                                ^
In file included from /usr/local/include/c++/6.1.0/map:61:0,
                 from tests/Graph.h:19,
                 from tests/test8c.cpp:3:
/usr/local/include/c++/6.1.0/bits/stl_map.h:1079:7: note: candidate: std::map<_Key, _Tp, _Compare, _Alloc>::iterator std::map<_Key, _Tp, _Compare, _Alloc>::find(const key_type&) [with _Key = std::__cxx11::basic_string<char>; _Tp = std::shared_ptr<gdwg::Graph<std::__cxx11::basic_string<char>, int>::Node>; _Compare = std::less<std::__cxx11::basic_string<char> >; _Alloc = std::allocator<std::pair<const std::__cxx11::basic_string<char>, std::shared_ptr<gdwg::Graph<std::__cxx11::basic_string<char>, int>::Node> > >; std::map<_Key, _Tp, _Compare, _Alloc>::iterator = std::_Rb_tree_iterator<std::pair<const std::__cxx11::basic_string<char>, std::shared_ptr<gdwg::Graph<std::__cxx11::basic_string<char>, int>::Node> > >; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = std::__cxx11::basic_string<char>]
       find(const key_type& __x)
       ^~~~

這是deleteNode的代碼。

template <typename N, typename E>
void Graph<N, E>::deleteNode(const N& node) noexcept {
    auto findNode = nodes_.find(node);
    if (findNode != nodes_.end()) {

        for (auto edge: findNode->second->incomingEdges_) {

            // find the node which has incoming edges into the deleted node
            auto originNodeOfIncomingEdge = edge->dest.lock(); // origin node of incoming edge to deleted node

            auto nodeVal = originNodeOfIncomingEdge->val_;
            std::cout << "Print out value of origin node of incoming edge to deleted node: " << nodeVal << std::endl;


            // delete the edge from the node
            //originNodeOfIncomingEdge->edges_.erase(edge);


            auto findLinkingNode1 = nodes_.find(originNodeOfIncomingEdge);
            if (findLinkingNode1 == nodes_.end()) throw std::runtime_error("deleteNode: findLinkingNode1 DNE");

        }

        findNode->second.reset(); // deletes managed object of the shared_ptr
        nodes_.erase(findNode); // removes the node from the map container


    }
}

以下是我的Graph類的一些聲明:

template <typename N, typename E> class Graph {

    private:
        struct Node;
        struct Edge;

        struct Node {
            N val_;
            int numEdges_;
            int numIncomingEdges_;
            std::set<std::shared_ptr<Edge>> edges_;
            std::set<std::shared_ptr<Edge>> incomingEdges_;
            Node() {}
            Node(const N x) : val_{x} { numEdges_=0; }
            void printNode(N n);
            ~Node();
            void update();
        };

        struct Edge {
            std::weak_ptr<Node> orig;
            std::weak_ptr<Node> dest;
            E val_;
            Edge(std::shared_ptr<Node> o, std::shared_ptr<Node> d, E x);
            Edge() {};
            void printEdge();
            ~Edge();
        };

在這里,編譯器說映射是使用std :: string類型的鍵構造的,而您正在使用Node類型的鍵來調用find。 您可以嘗試auto findLinkingNode1 = nodes_.find(originNodeOfIncomingEdge->val_); 最好共享void Graph<N, E>::deleteNode(const N& node) noexcept和Graph對象的實例化的調用。

該錯誤表明originNodeOfIncomingEdge類型為std::shared_ptr<gdwg::Graph<std::__cxx11::basic_string<char>‌​, int>::Node>而不是std::string

我相信這就是您想要的:

auto findLinkingNode1 = nodes_.find(nodeVal);
if (findLinkingNode1 == nodes_.end())
   // logic to handle

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 錯誤:沒有匹配的函數調用&#39;std::__cxx11::basic_string<char> ::basic_string(int&amp;)&#39; 錯誤:沒有匹配函數來調用&#39;std :: vector <std::__cxx11::basic_string<char> &gt; ::的push_back(INT&)” 第 5 行:字符 54:錯誤:沒有匹配的 function 調用 'min(int, std::__cxx11::basic_string<char> ::尺碼類型)'</char> C++ 錯誤:沒有匹配的函數調用&#39;std::__cxx11::basic_string<char> ::附加<int> (int, int)&#39; 錯誤:沒有匹配的函數調用&#39;std :: vector <std::vector<int> &gt; ::的push_back(標准::矢量 <std::__cxx11::basic_string<char> &gt;&)” 錯誤:無法從“向量”轉換“標簽” <std::vector<std::__cxx11::basic_string<char> &gt;&gt;' 到 ' 向量<std::__cxx11::basic_string<char> &gt;' </std::__cxx11::basic_string<char></std::vector<std::__cxx11::basic_string<char> 錯誤:沒有匹配的函數調用&#39;std::basic_ifstream<char> ::basic_ifstream(std::__cxx11::string&amp;)&#39; 錯誤:為&#39;operator std::string {aka std::__cxx11::basic_string 指定的返回類型<char> }&#39; 錯誤:傳遞&#39;const字符串{aka const std :: __ cxx11 :: basic_string <char> }&#39;作為&#39;this&#39;參數 錯誤:“operator+=”不匹配(操作數類型為“long double”和“std::__cxx11::basic_string”<char> &#39;)
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM