c++ - 不同的函数签名 C++
问题描述
发现了一些 C++ 测试,其中一个问题是:函数签名之间的差异是什么。我对以下答案是否正确?
void f(data); // 1)calls copy constructor of data to pass in function
void f(data*); // 2)data passes to function by ptr, no copy constructor called
void f(data const*); // 3)same as 2, but not allowed to change pointer, allowed to change data
void f(data* const); // 4)same as 2, but not allowed to change data, allowed to change pointer
void f(data const* const); // 5) same as 2, niether ptr and data can be changed
void f(data&); // 6) same as 2, but ref instead of ptr
void f(data const&); // 7) same as 3
void f(data&&); // 8) Refence to reference(most subtle moment to me), move constructor, depends on function original data can be erased
解决方案
不完全的:
-
- 不一定要复制。其他构造函数可用于初始化参数。
-
- 和 4. 是错误的方式。
-
- 没有“参考参考”之类的东西。那是一个右值引用。绑定对值的引用时不调用构造函数。
推荐阅读
- sql-server-2005 - 从 JAVA 8 连接到 SQL Server 2005
- c# - 不计算文本框中的空白
- java - 如何在将 targetSdkVersion 从版本 25 升级到 27 时修复错误?
- python-3.x - Discord Bot 无法访问文本文件
- pointers - 将 D 对象指针转换为 void* 并传递给回调
- ruby-on-rails - 新页面正确获取资源,但编辑页面没有
- javascript - 将确切的数字和字符串与两者中的任何内容匹配
- c# - 如何在类/单独的线程 ASP.Net Core 中使用 ApplicationDbContext
- xml - 使用 Powershell 按列号拆分 CSV 文件
- ansible - Ansible - 是否可以向库存中的主机添加标签?