Hash table as return type of a function in C++

一世执手 提交于 2019-12-13 08:15:06

问题


I would like to know if I can use Hash table as a return type of a function in C++. :)


回答1:


The C++ standard library implementation of a hash table is std::unordered_map and yes, you can happily return it from a function:

std::unordered_map<X, Y> foo() {
  std::unordered_map<X, Y> map;
  return map;
}

It can be copied because it has a copy constructor. If you implement your own hash table, it will also be returnable if it has a copy constructor.

† In C++11, a move constructor will be sufficient for the example given.



来源:https://stackoverflow.com/questions/15114790/hash-table-as-return-type-of-a-function-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!