其实我不知道如何定义这个成语。
在某些代码中,我有红色的东西,如下所示:
ClassWithAMessage c = "This is the message";
我期望阅读的地方:
ClassWithAMessage c("This is the message");
我不知道如何重现这种行为,有人可以提供一些信息或玩具示例吗?
ClassWithAMessage c = "This is the message";
是副本初始化。复制构造函数必须可用才能正常工作。首先,使用 "This is the message"
中的转换构造函数构造临时ClassWithAMessage
。然后,临时与复制构造函数一起使用以构造c
。这受复制省略的影响(温度可能不存在)。
ClassWithAMessage c("This is the message");
是直接初始化。转换构造函数直接使用。
不是真正的成语,只是构造对象的不同方法。