在C++中初始化带有和不使用构造函数调用的对象有什么区别

What is the difference between initialising an object with and without a constructor call in C++

本文关键字:函数调用 区别 什么 对象 C++ 初始化      更新时间:2023-10-16

In C++14 当我们有

class A{};

如果我们在下面的表格中初始化类A的对象

A a = A();

不是传统上

A a;

那么A a = A();会发生什么?

在 C++17 之前,可能会发生复制省略,否则您有移动/复制构造函数调用,但无论如何移动/复制构造函数应该可用。

自 C++17 以来,不会发生任何复制/移动构造函数(并且不需要访问(。