簡體   English   中英

C++:無法插入一對<int, MLine*>到 unordered_map

[英]c++: Can't insert a pair<int, MLine*> to an unordered_map

我將 my_map 定義為:

 std::unordered_map<MyAction, MyLine * >;

(MyAction 是一個枚舉類)

其中 MyLine 是std::vector<MyPoint>

MyLines 是std::vector<MyLine> MyLine std::vector<MyLine>

然后使用以下代碼:

for (const auto &myline : mylines) {

            my_map.insert(
                std::pair<MyAction, const Myline *>(MyAction::KEEP_1, &myline));

我收到以下錯誤:

my_utility.cpp:85:33: error: no matching member function for call to 'insert'
            my_map.insert(
            ~~~~~~~~~~~~~~~~~~~~^~~~~~
my_project/external/clang/darwin/include/c++/v1/unordered_map:909:26: note: candidate function not viable: no known conversion from 'pair<my_namespace::MyAction, const Myline *>' to 'const pair<const std::__1::unordered_map<my_namespace::MyAction, std::__1::vector<math::Vector3<double>, std::__1::allocator<math::Vector3<double> > > *, std::__1::hash<my_namespace::MyAction>, std::__1::equal_to<my_namespace::MyAction>, std::__1::allocator<std::__1::pair<const MyAction, std::__1::vector<math::Vector3<double>, std::__1::allocator<math::Vector3<double> > > *> > >::key_type, std::__1::unordered_map<my_namespace::MyAction, std::__1::vector<math::Vector3<double>, std::__1::allocator<math::Vector3<double> > > *, std::__1::hash<my_namespace::MyAction>, std::__1::equal_to<my_namespace::MyAction>, std::__1::allocator<std::__1::pair<const MyAction, std::__1::vector<math::Vector3<double>, std::__1::allocator<math::Vector3<double> > > *> > >::mapped_type>' for 1st argument
    pair<iterator, bool> insert(const value_type& __x)
                         ^

知道出了什么問題嗎? 謝謝!

你的地圖有MyLine *但在插入函數中你也寫了const 刪除它,它應該可以工作。

暫無
暫無

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM