A private constructor is a special instance constructor.
私有构造函数是一种特殊的实例构造函数。
The following is an example of a class using a private constructor.
以下是一个类别使用私用建构函式的范例。
Do classes that should not be instantiated have a private constructor?
不需要实例化的类有私有构造函数吗?
What is the difference between a class having private constructor and a sealed class having private constructor?
的区别是什么类拥有私有构造函数和一个密封的类有私有构造函数吗?
You could still accidentally use a private constructor (e. g. in a restricted set of scopes), but the compiler will forbid you from ever using a deleted constructor.
你仍然可以不小心使用了私有的构造方法(例如,在一组限制的范围),但编译器将禁止你使用过删除构造函数。
If a class contains only static members, remember to mark the class as static or seal the class (NotInheritable) and give the class a private constructor to avoid instance creation.
如果类只包含静态成员,则要记得将该类标记为静态,或者密封该类(NotInheritable),并且还要为该类提供一个私有构造函数,以避免实例创建。
Listing 2 shows a piece of code that results in a compile-time error because the copy constructor is private.
清单2显示了产生编译时错误的代码部分,因为该拷贝构造函数是私有的。
You should mark this constructor private so that you can't accidentally call the constructor and forget to record it in your object map.
应当将此构造器标识为私有,这样就不会意外调用构造器并忘记将它记录到对象映射中。
The argument to the constructor is the fully qualified URL of the metadata service being exposed, which we construct using methods in the private class HostDescriptor.
该构造函数的参数是正在被显示的元数据服务的全限定url,我们使用私有类HostDescriptor中的方法构造了它。
Note that we declare the LogonUI constructor as private.
请注意,我们把构造函数 LogonUI声明为 private。
HierarchyBuilder's constructor is private, however, so I can't test it via my test class (nor do I care to); therefore, my line coverage still hovers at 88%.
然而,因为HierarchyBuilder的构造器是private类型的,所以我不能通过我的测试类测试它(我也不关心)。因此,我的行覆盖率仍然只有88%。
Also, for classes that have design reasons to have private or no copy constructor, this style of swapping won't work. Here's what boost: : swap gets you.
另外,对于出于设计原因拥有private构造函数而没有复制构造函数的类,所以这种交换风格不适用。
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.
在第一种情况下,你基本上是声明一个私有拷贝构造函数,然后没有提供任何实现。通过声明他们私人,非成员国不能复制它。
Making it private is the "old" way of doing it. The constructor still exists, but it is private, and can only be invoked from within another class member function.
使其私人的“旧”的方式这样做。构造函数仍然存在,但它是私人的,只能从内部调用另一个类的成员函数。
We add a constructor that also defines a private property.
添加一个构造函数,并定义一个私有属性。
If you're using a framework that requires this for some reason, see if you can satisfy it by providing a private no-argument constructor (which is visible via reflection).
如果您正在使用的框架因为某些原因需要使用这样的构造函数的话,那么您可以了解以下能否通过提供一个私有的无参数构造函数(这是经由反射可见的)来满足这一要求。
The noncopyable class definition presents no surprises, as the copy constructor and operator= are declared private.
noncopyable类定义没有什么令人感到新奇的地方,因为copyconstructor和operator= 声明为 private。
Your first solution conveys to the reader that the copy-constructor is private and is not to be used.
你的第一个解决方案向读者传达,拷贝构造函数是私有的,不能使用。
The traditional way to solve this is to declare the copy-constructor private and to leave it unimplemented.
传统的方式来解决这个是声明拷贝构造函数私有和未实现的。
Which is the difference between declaring a constructor private and =delete?
声明一个构造函数的区别是私人和=删除?。
The special constructor used for serialization should also perform thorough input validation and should be either protected or private to help protect against misuse by malicious code.
用于序列化的特殊构造函数也应当进行彻底的输入验证,并且应当成为被保护的或者私有的,以帮助防范恶意代码的滥用行为。
Ruby class initialize (constructor) is private method or public method?
宝石类初始化(构造函数)是私人或公共方法方法?
The first case is redundant, why declare the copy constructor, make it private, and not implement it.
第一个病例是多余的,为什么声明拷贝构造函数,使其私人,不实现它。
Do declare static classes as sealed and abstract, and add a private instance constructor, if your programming language does not have built-in support for static classes.
如果编程语言没有对静态类的内置支持,则应将静态类声明为密封的和抽象的,并添加一个私有实例构造函数。
In the first case, you are essentially declaring a private copy constructor and then not providing any implementation.
在第一种情况下,你基本上是声明一个私有拷贝构造函数,然后没有提供任何实现。
If a static constructor is not private, it can be called by code other than the system.
如果静态构造函数不是私有,则系统以外的代码可以调用它。
The programming language compiler added a default static constructor to your type and did not make it private.
编程语言编译器已向您的类型中添加默认静态构造函数,但未将其设置为私有。
So just making a constructor private doesn't communicate the intention very well, and the resulting error is not very clear, either.
所以仅仅做一个构造函数私有并不交流意图很好,和由此产生的错误也不是很清楚,。
Note that if you do not use an access modifier with the constructor it will still be private by default.
注意,如果您不对构造函数使用访问修饰符,则在默认情况下它仍为私有构造函数。
The constructor still exists, but it is private, and can only be invoked from within another class member function.
构造函数仍然存在,但它是私人的,只能从内部调用另一个类的成员函数。
应用推荐