簡體   English   中英

C++:擴展已創建的 C 結構與自定義 hash 和可在 unordered_map 中使用的相等功能

[英]C++: Extend already created C struct with custom hash and equal functions to be usable in unordered_map

我有兩個項目,一個寫在 C 中,另一個寫在 C++ 中。 我需要在我的 C++ 程序中的 unordered_map 中使用 C 結構。 如何通過 hash 擴展結構並比較 function 以便我不必總是將這些函數傳遞給 unordered_map?

在結構外部定義==運算符(這是允許的)並在 C++ 文件中為您的結構專門std::hash 請參閱 cppreference 中的示例: https://en.cppreference.com/w/cpp/utility/hash

暫無
暫無

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

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