由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - C++ Q47: protected constructor (C39)
相关主题
C++ online Test请问:什么情况下singleton will fail?
C++ online Test 一题发面经攒rp —— Bloomberg
c++ class default functions?问一个关于引用和指针的问题
问个C++ ctor的问题关于singleton 的面试题
One C++ question[请教] C++ coding question
问个构造函数的问题Qualcomm Phone Interbview面筋,赚RP
请问这个C++问题对吗?贴一道take home的面试题
康州金融公司 Interactive Broker , AQR 面经今早Bloomberg电话面试经过,奉献给大家。。。
相关话题的讨论汇总
话题: someclass话题: ensure话题: class话题: protected
进入JobHunting版参与讨论
1 (共1页)
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

1 (共1页)
进入JobHunting版参与讨论
相关主题
今早Bloomberg电话面试经过,奉献给大家。。。One C++ question
新Qualcomm面经问个构造函数的问题
再帖一遍Amazon Onsite的题请问这个C++问题对吗?
Bloomberg网上测试题康州金融公司 Interactive Broker , AQR 面经
C++ online Test请问:什么情况下singleton will fail?
C++ online Test 一题发面经攒rp —— Bloomberg
c++ class default functions?问一个关于引用和指针的问题
问个C++ ctor的问题关于singleton 的面试题
相关话题的讨论汇总
话题: someclass话题: ensure话题: class话题: protected