您知道Set有一个拷贝构造函数。
这是一个有效的拷贝构造函数吗?
现在拷贝构造函数是一个好方法。
调用拷贝构造函数不存在!
建模构造函数、分析构造函数,以及拷贝构造函数。
你应该创建一个拷贝构造函数的每个对象自己。
You should create a copy constructor for each object yourself.
拷贝构造函数只在需要的情况下动态内存分配吗?
Copy constructor is needed only in the case of dynamic memory allocation?
c++标准的允许拷贝构造函数要省略在某些情况下。
The C++ standard allows for the copy constructor to be elided in certain situations.
保护的想法是创建一个拷贝构造函数除了默认构造函数。
The idea is to create a protected copy constructor aside from the default constructor.
传统的方式来解决这个是声明拷贝构造函数私有和未实现的。
The traditional way to solve this is to declare the copy-constructor private and to leave it unimplemented.
清单2显示了产生编译时错误的代码部分,因为该拷贝构造函数是私有的。
Listing 2 shows a piece of code that results in a compile-time error because the copy constructor is private.
你的第一个解决方案向读者传达,拷贝构造函数是私有的,不能使用。
Your first solution conveys to the reader that the copy-constructor is private and is not to be used.
第一个病例是多余的,为什么声明拷贝构造函数,使其私人,不实现它。
The first case is redundant, why declare the copy constructor, make it private, and not implement it.
赋值运算符是应用于一个初始化的对象,但这并不是拷贝构造函数的情况下。
The assignment operator is applied on a initialized object, but this is not the case in the copy constructor.
放在单独的功能调用析构函数和拷贝构造函数和赋值运算符你所需要的功能。
Put the functionality you need in separate functions called by the destructor and the copy constructor and the assignment operator.
在第一种情况下,你基本上是声明一个私有拷贝构造函数,然后没有提供任何实现。
In the first case, you are essentially declaring a private copy constructor and then not providing any implementation.
如果你没有为拷贝构造函数写正确的代码,就有可能造成list中对象的某些数据成员没有初始化。
If you do not write a correct code for the copy constructor, object within a list will have some data members uninitialized.
经常我渴望一个拷贝构造函数初始化成员变量作为一个副本,而不是默认的构造,然后分配。
Often I desire a copy constructor which initializes each member variable as a copy, rather than default constructing and then assigning. e. g.
对于类对象包含指针的情况下,我们要编写自己的拷贝构造函数,这样可以防止上述情况的发生。
For a situation where an object contain Pointers we have to write our own copy constructor that will prevent situations like those mentioned above.
每个类(其实例要在容器内使用)必须至少实现拷贝构造函数(实现赋值运算符,也是好习惯)。
Each class whose instance will go into the container must implement at least the copy constructor it is good to implement also the assignment operator.
有什么方法可以利用隐式的拷贝构造函数初始化列表吗?有没有其他方式手动编写初始化列表吗?
Is there any way to make the implicit copy constructor use initialization lists? Is there any other way around manually writing the initialization list?
再一次,如果你不提供一个拷贝构造函数,编译器生成一个你,再一次复制使用拷贝构造函数成员。
Again, if you don't provide a copy constructor, the compiler generates one for you, again just copying the members using the copy constructor.
拷贝构造函数是一种特别的构造函数,用于复制已经存在的对象到新生成的对象,这是一种高效的方式。
The copy constructor is a special kind of constructor which creates a new object which is a copy of an existing one, and does it efficiently.
由于模板构造函数终究不是拷贝构造函数,因此这种模板的出现并不会隐藏原来隐含的拷贝构造函数之声明。
Because a template constructor is never a copy constructor, the presence of such a template does not suppress the implicit declaration of a copy constructor.
问题:手动编写一个拷贝构造函数的初始化每个成员变量作为副本很乏味,和近乎荒谬的成员变量数量的增加。
Question: Manually writing a copy constructor which initializes each member variable as a copy is very tedious, and verges on ridiculous as the number of member variables grows.
我们都知道,这个隐式的拷贝构造函数操作如下:默认构建所有成员变量,然后分配每个成员变量相应的对应值。
We all know that the implicit copy constructor operates as follows: default construct all member variables, then assign each member variable the appropriate corresponding value.
在第一种情况下,你基本上是声明一个私有拷贝构造函数,然后没有提供任何实现。通过声明他们私人,非成员国不能复制它。
In the first case, you are essentially declaring a private copy constructor and then not providing any implementation. By declaring them private, non-members cannot copy it.
虽然实现是允许省略拷贝,一个可行的和可访问的拷贝构造函数(或移动构造函数,如果我们谈论的是一个移动)应该是仍然存在的。
Even though an implementation is allowed to elide the copy, a viable and accessible copy constructor (or move constructor, if we're talking about a move) should still be present.
如果程序员没有提供拷贝构造函数,那么编译器会自动生成默认的拷贝构造函数。默认的拷贝构造函数会执行简单的操作,即按位拷贝对象。
Default copy constructor does a very simple operation, they will do a bit-wise (member-wise) copy of an object, which means that the object will be copied bit by bit.
如果程序员没有提供拷贝构造函数,那么编译器会自动生成默认的拷贝构造函数。默认的拷贝构造函数会执行简单的操作,即按位拷贝对象。
Default copy constructor does a very simple operation, they will do a bit-wise (member-wise) copy of an object, which means that the object will be copied bit by bit.
应用推荐