c++ - "MyClass a(anotherInstance);"比 "MyClass a = anotherInstance;"快吗?

标签 c++ constructor latency

我目前正在重新设计一位同事的代码。我发现他经常使用这样的语法

double a(anotherDouble);  --- A

代替

double a = anotherDouble;  --- B

我想知道他的语法是否更快,也许方法A可以节省构造函数操作?

有人可以在这里提供一些见解吗?

谢谢,祝您假期愉快!

最佳答案

对于内置数据类型double,它们都是相同的,没有性能差异。

在自定义类的情况下。
第一个是直接初始化,第二个是复制初始化

好读:

Is there a difference between copy initialization and direct-initialization

关于c++ - "MyClass a(anotherInstance);"比 "MyClass a = anotherInstance;"快吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8634455/

相关文章:

c++ - 如何使用 LoadImage 和 StretchDIBits 绘制 PNG 图像?

python - 使用 C/API 和 C++ 类编写 Python 模块

c++ - 通过 dll 边界传递对 STL vector 的引用

android - 奇怪的 "stutter"在不同的 android 设备上的 box2D

list - 在Dart中作为可选构造函数参数列出的列表为null

android - 替换弃用的 GestureDetector 构造函数

c# - 将 C# Ctor 翻译成 Vb.Net 等价物

c - 测量一组指令的准确时间(周期数)

postgresql - 模拟 AKS 中的应用程序与 Azure 中的 PostgreSQL 服务器之间的网络延迟

performance - 什么是 L1 Cache Reference 或 Main Memory Reference