gpt4 book ai didi

c++ - 隐式拷贝构造函数

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:24:57 24 4
gpt4 key购买 nike

引自 n3337 12.3.1/3

A non-explicit copy/move constructor (12.8) is a converting constructor. An implicitly-declared copy/move constructor is not an explicit constructor; it may be called for implicit type conversions.

引自 ANSI ISO IEC 14882 2003

A non-explicit copy-constructor (12.8) is a converting constructor. An implicitly-declared copy constructor is not an explicit constructor; it may be called for implicit type conversions.

我不知道如何将copy-constructor 用于隐式 类型转换。如果它是标准中的打印错误/错误,为什么自 C++03 标准以来没有更正?非常感谢任何链接和示例(如果我们可以将其用于类型转换)。

最佳答案

复制构造函数可以通过切片从派生类型的对象转换:

struct A {};
struct B : A {};

B b;
A a = b; // uses A::A(A const&) to convert B to A

关于c++ - 隐式拷贝构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12428308/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com