c**********e 发帖数: 2007 | 1 class someClass {
protected:
someClass() {}
someClass(const someClass&) {}
};
Why are the default and copy constructors declared as protected?
a) To ensure that instances of someClass can only be created by its subclass
b) To ensure that someClass can not be used as a base class
c) To ensure that instances of someClass cannot be copied.
d) To ensure that someClass cannot be instantiated on the stack
e) To ensure that instances of someClass cannot be created via new by a more
derived cl |
s*********t 发帖数: 1663 | 2 a?
subclass
【在 c**********e 的大作中提到】 : class someClass { : protected: : someClass() {} : someClass(const someClass&) {} : }; : Why are the default and copy constructors declared as protected? : a) To ensure that instances of someClass can only be created by its subclass : b) To ensure that someClass can not be used as a base class : c) To ensure that instances of someClass cannot be copied. : d) To ensure that someClass cannot be instantiated on the stack
|
M********5 发帖数: 715 | 3 I think the answer is c. |
K******g 发帖数: 1870 | 4 好像都不太准确。相比较之下,选a吧。
但是someClass还是可以被created by a member or friend function.
subclass
【在 c**********e 的大作中提到】 : class someClass { : protected: : someClass() {} : someClass(const someClass&) {} : }; : Why are the default and copy constructors declared as protected? : a) To ensure that instances of someClass can only be created by its subclass : b) To ensure that someClass can not be used as a base class : c) To ensure that instances of someClass cannot be copied. : d) To ensure that someClass cannot be instantiated on the stack
|
c**********e 发帖数: 2007 | 5 I do not have an answer. High-hand, help please. |
M********5 发帖数: 715 | 6 这题显然a不对
这个类明明可以定义一个public的函数来调用ctor,这就是singleton的一种实现方式
,我觉得这题就是c |
N**********d 发帖数: 9292 | 7 c?
subclass
【在 c**********e 的大作中提到】 : class someClass { : protected: : someClass() {} : someClass(const someClass&) {} : }; : Why are the default and copy constructors declared as protected? : a) To ensure that instances of someClass can only be created by its subclass : b) To ensure that someClass can not be used as a base class : c) To ensure that instances of someClass cannot be copied. : d) To ensure that someClass cannot be instantiated on the stack
|
N**********d 发帖数: 9292 | 8 它本身可以实例化自己
【在 s*********t 的大作中提到】 : a? : : subclass
|
M********5 发帖数: 715 | 9 我是这个意思
【在 N**********d 的大作中提到】 : 它本身可以实例化自己
|
s*****t 发帖数: 737 | 10 Then tell me why it cannot call the copy costructor by using the same method.
这题显然a不对
这个类明明可以定义一个public的函数来调用ctor,这就是singleton的一种实现方式
,我觉得这题就是c
【在 M********5 的大作中提到】 : 这题显然a不对 : 这个类明明可以定义一个public的函数来调用ctor,这就是singleton的一种实现方式 : ,我觉得这题就是c
|
t****t 发帖数: 6806 | 11 a
要做singleton就用private了. 用protected本身就暗示答案跟子类相关.
【在 M********5 的大作中提到】 : I think the answer is c.
|
A*******1 发帖数: 985 | 12 Is that a Java question?
Then I think e is right.
you can not use protected constructor in a class that extends the
constructor's class. You have to call super() in inheriting class to invoke
the protected constructor in base class. for example:
Class B extends SomeClass
{
public B()
{
super();
}
somemethod()
{
SomeClass a = new SomeClass(); //wrong, unless SomeClass's constructor is
public
B b = new B(); // right
}
} |
t****t 发帖数: 6806 | 13 the title reads "C++ Q47..."
invoke
【在 A*******1 的大作中提到】 : Is that a Java question? : Then I think e is right. : you can not use protected constructor in a class that extends the : constructor's class. You have to call super() in inheriting class to invoke : the protected constructor in base class. for example: : Class B extends SomeClass : { : public B() : { : super();
|
s*********t 发帖数: 1663 | 14 全错
subclass
【在 c**********e 的大作中提到】 : class someClass { : protected: : someClass() {} : someClass(const someClass&) {} : }; : Why are the default and copy constructors declared as protected? : a) To ensure that instances of someClass can only be created by its subclass : b) To ensure that someClass can not be used as a base class : c) To ensure that instances of someClass cannot be copied. : d) To ensure that someClass cannot be instantiated on the stack
|