---
title: "#perfect-forwarding articles | Hashnode"
description: "Explore 1 articles tagged #perfect-forwarding on Hashnode. Tutorials, guides, and how-tos from the community."
url: "https://hashnode.com/tag/perfect-forwarding"
---

Tag

# #perfect-forwarding

1 posts · 0 followers

[qilingzhao](https://hashnode.com/@Zhao70) · [Jul 23, 2022](https://hashnode.com/posts/cpp-11-perfect-forwarding/62dba99738759e6b49829afc)

### [C++11中的完美转发](https://qilingzhao.com/cpp-11-perfect-forwarding?utm_source=hashnode&utm_medium=feed)

背景问题 我们想要创建创建一个工厂模版函数factory, 使用Arg类型的参数arg，构造一个T对象，并返回它的shared\_ptr, 我们的理想是factory就像不存在一样，因此我们需要一个完美转发(perfect forwarding): 如果参数是 左值引用，直接以 左值引用 的形式，转发给下一个函数 如果参数是 右值引用，要先 “还原” 为 右值引用 的形式，再转发给下一个函数 解决方案 完美转发的两个特定，对应着两个要求 必须按引用传递；且左值和右值必须都能引用 若引用右值，...

1 min read · [qilingzhao.com](https://qilingzhao.com/cpp-11-perfect-forwarding?utm_source=hashnode&utm_medium=feed)
