gpt4 book ai didi

c++ - 引用TC++PL第3版10.4.6.3 "copying members"部分

转载 作者:行者123 更新时间:2023-11-30 03:04:10 26 4
gpt4 key购买 nike

这句话是什么意思?

A default copy constructor or default copy assignment copies all elements of of the class. If this copy cannot be done, it is an error to try to copy an object of class.

例如:

class unique_handle{    
unique_handle(const unique_handle&);
unique_handle&operator=(const unique_handle&);
public ://...
};

struct Y {
unique_handle a;
}//require explicit initialization
Y y1;
Y y2=y1; //error:cannot copy Y::a

最佳答案

如果您的类包含无法复制的元素(unique_handle 具有私有(private)复制构造函数,因此它确实无法复制),则不可能进行元素复制。

关于c++ - 引用TC++PL第3版10.4.6.3 "copying members"部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8895904/

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