Hash表作为C ++中函数的返回类型 [英] Hash table as return type of a function in C++

查看:110
本文介绍了Hash表作为C ++中函数的返回类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如果我可以使用Hash表作为C ++函数的返回类型。
:)

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

推荐答案

哈希表的C ++标准库实现 std :: unordered_map 是的,你可以从一个函数中快乐地返回它:

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;
}

可以复制它,因为它有一个副本构造函数 sup>。

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.

†在C ++ 11中,一个移动构造函数将会被创建对于给定的示例是足够的。

这篇关于Hash表作为C ++中函数的返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆