由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - C++做题,麻烦师傅们再看看。
相关主题
C++ online Test 2题请教goodbug等大神几个AWS的问题
C++问题几个how to create an instance of base class in its derived class definition
请教高手一个C++问题[合集] C++ private member question
怎么把const T& 作为一个class的member请教C++面试题
问一个java基础的初始化的问题,一直搞不明白请问关于c++实现singleton的问题?
How to make sure that I get the original object or only a copy (not original) in such situation?再一个问题c++
another c++ interview questionHow to understand the answer.
[c++] static function in a class弱问,上哪儿去找服务器?
相关话题的讨论汇总
话题: ensure话题: c++话题: class话题: instances话题: instance
进入Programming版参与讨论
1 (共1页)
z****e
发帖数: 2024
1
多选题
in the sample code, why are the default and copy constructors declared as
protected?
class A
{
public:
void f();
protected:
A()
{
cout << "A:A()" << endl;
}
A(const A&){}
};
A. To ensure that instances of A cannot be copied
B. To ensure that instances of A cannot be created via new by a more derived
class
C. To ensure that instances of A can only be created by subclasses of A
D. To ensure that A cannot be instantiated on the stack
E. To ensure that A cannot be used as a base class
A.
师傅们能确认一下吗?
z****e
发帖数: 2024
2
instances of A,应该是完全无法生成吧?派生类里那个,不能叫instance of A吧。
G*****7
发帖数: 1759
3
Why not fire up vs/eclipse and find out for yourself?
This is not like the macro vs template thing. I d understand if ppl don't
lend u a hand this time.

【在 z****e 的大作中提到】
: 多选题
: in the sample code, why are the default and copy constructors declared as
: protected?
: class A
: {
: public:
: void f();
: protected:
: A()
: {

X****r
发帖数: 3557
4
我都不想再说了,你做这种题毫无意义。既不会提高你编程能力也不能增加你面试成功
机会。

【在 z****e 的大作中提到】
: 多选题
: in the sample code, why are the default and copy constructors declared as
: protected?
: class A
: {
: public:
: void f();
: protected:
: A()
: {

z****e
发帖数: 2024
5
大哥,我这找师傅们求证呢,你不愿意当师傅没人求着您。

【在 G*****7 的大作中提到】
: Why not fire up vs/eclipse and find out for yourself?
: This is not like the macro vs template thing. I d understand if ppl don't
: lend u a hand this time.

z****e
发帖数: 2024
6
师傅,这就面试题啊。
不为了面试,谁没事整这八股。
连iso::goodbit failbit都来了。

【在 X****r 的大作中提到】
: 我都不想再说了,你做这种题毫无意义。既不会提高你编程能力也不能增加你面试成功
: 机会。

X****r
发帖数: 3557
7
C
你真的面试过一家公司问你这种题吗?反正我是没听说过。

【在 z****e 的大作中提到】
: 师傅,这就面试题啊。
: 不为了面试,谁没事整这八股。
: 连iso::goodbit failbit都来了。

m*******l
发帖数: 12782
8
估计是online的题库,时不时bloomberg?

【在 X****r 的大作中提到】
: C
: 你真的面试过一家公司问你这种题吗?反正我是没听说过。

z****e
发帖数: 2024
9
是面题。
答案你再想想吧。我觉得你错了。
“A base class is sometimes called a superclass and a derived class a
subclass.” The C++ programming Lan..
subclass 是派生类,无法实例化A,更无法拷贝。其实这也是我问一下讨论确认的原因
所在。
实在想不出实例化A的方法。师傅有没有招?

【在 X****r 的大作中提到】
: C
: 你真的面试过一家公司问你这种题吗?反正我是没听说过。

z****e
发帖数: 2024
10
面不起这么贵的公司。我们都是小本经营。

【在 m*******l 的大作中提到】
: 估计是online的题库,时不时bloomberg?
相关主题
How to make sure that I get the original object or only a copy (not original) in such situation?请教goodbug等大神几个AWS的问题
another c++ interview questionhow to create an instance of base class in its derived class definition
[c++] static function in a class[合集] C++ private member question
进入Programming版参与讨论
X****r
发帖数: 3557
11
The sub-object of A in an instance of B is an instance of A.

【在 z****e 的大作中提到】
: 是面题。
: 答案你再想想吧。我觉得你错了。
: “A base class is sometimes called a superclass and a derived class a
: subclass.” The C++ programming Lan..
: subclass 是派生类,无法实例化A,更无法拷贝。其实这也是我问一下讨论确认的原因
: 所在。
: 实在想不出实例化A的方法。师傅有没有招?

z****e
发帖数: 2024
12
这句话能给个出处吗?
因为对于instance of A的定义不同,答案就不一样。

【在 X****r 的大作中提到】
: The sub-object of A in an instance of B is an instance of A.
X****r
发帖数: 3557
13
No, 'instance' is not a technical term used in the Standard,
so there is probably no single answer accepted by everyone.
This is exact why this kind of question is pointless.
However, the Standard does mention it in one place:
In C++03 10.2 6, or C++11 10.2 11, it uses 'instance' to
refer a particular sub-object.

【在 z****e 的大作中提到】
: 这句话能给个出处吗?
: 因为对于instance of A的定义不同,答案就不一样。

z****e
发帖数: 2024
14
师傅,你自己先gcc一把行吗???
难道我的编译器出轨了?
class A
{
public:
void f();
protected:
A()
{
cout << "A:A()" << endl;
}
A(const A&){}
};
class B : public A {
static void test() {
A a;//明显的报错
A b = a;
A *c = new A;
}
};
int main(int argc, char* argv[]){
}
z****e
发帖数: 2024
15
你说的没错。从pointless到standard。的确instance可以是subobject。赞学术态度。
这就一个八股。
需要不是subobject的A,能有方法实例化吗?

【在 X****r 的大作中提到】
: No, 'instance' is not a technical term used in the Standard,
: so there is probably no single answer accepted by everyone.
: This is exact why this kind of question is pointless.
: However, the Standard does mention it in one place:
: In C++03 10.2 6, or C++11 10.2 11, it uses 'instance' to
: refer a particular sub-object.

l*********s
发帖数: 5409
16
It is not 八股, copy and ctor concepts are fundamental to C++. You don't
realize its importance, you can't be a competent C++ programmer.


【在 z****e 的大作中提到】
: 你说的没错。从pointless到standard。的确instance可以是subobject。赞学术态度。
: 这就一个八股。
: 需要不是subobject的A,能有方法实例化吗?

p***o
发帖数: 1252
17
这我还真没注意过 ...

【在 z****e 的大作中提到】
: 师傅,你自己先gcc一把行吗???
: 难道我的编译器出轨了?
: class A
: {
: public:
: void f();
: protected:
: A()
: {
: cout << "A:A()" << endl;

z****e
发帖数: 2024
18
智者千虑。。。
师傅还是师傅。
不过我刚看见你的代码的时候,非常惊叹于自己的无知,原来static能改变access。
犹豫了一下,没急着回帖,gcc一把,我靠,原来师傅也有诈和相公的时候啊。。。。

【在 p***o 的大作中提到】
: 这我还真没注意过 ...
X****r
发帖数: 3557
19
No, unless A creates one itself or via a friend class/function.

【在 z****e 的大作中提到】
: 你说的没错。从pointless到standard。的确instance可以是subobject。赞学术态度。
: 这就一个八股。
: 需要不是subobject的A,能有方法实例化吗?

z****e
发帖数: 2024
20
仔细看题,A的scope里边没有friend。

【在 X****r 的大作中提到】
: No, unless A creates one itself or via a friend class/function.
相关主题
请教C++面试题How to understand the answer.
请问关于c++实现singleton的问题?弱问,上哪儿去找服务器?
再一个问题c++Global(static) variable initialization question
进入Programming版参与讨论
z****e
发帖数: 2024
21
知八股者,红猪侠师傅是也。

【在 l*********s 的大作中提到】
: It is not 八股, copy and ctor concepts are fundamental to C++. You don't
: realize its importance, you can't be a competent C++ programmer.
:

p***o
发帖数: 1252
22
没用过就是没用过啊, 通常这种static memeber直接就return new B了。
考虑到B()是可以用protected的A()来初始化基类的,我原以为access
control这里就去掉了。谁知道基类和member的处理居然不一样 ...
看看标准再说。

【在 z****e 的大作中提到】
: 智者千虑。。。
: 师傅还是师傅。
: 不过我刚看见你的代码的时候,非常惊叹于自己的无知,原来static能改变access。
: 犹豫了一下,没急着回帖,gcc一把,我靠,原来师傅也有诈和相公的时候啊。。。。

JS
发帖数: 199
23
处理好像是一样的
stackoverflow有标准答案

【在 p***o 的大作中提到】
: 没用过就是没用过啊, 通常这种static memeber直接就return new B了。
: 考虑到B()是可以用protected的A()来初始化基类的,我原以为access
: control这里就去掉了。谁知道基类和member的处理居然不一样 ...
: 看看标准再说。

JS
发帖数: 199
24
红猪怎么变成思考猪了?
factory pattern

【在 X****r 的大作中提到】
: No, unless A creates one itself or via a friend class/function.
z****e
发帖数: 2024
25
是啊,哪怕再简单的题贴出来都是有意义的。
即便是师傅,也难辨考虑不周。所以这些题目的讨论才富有乐趣和意义。
感谢师傅们百忙中冒着答案出错和被老婆骂不倒垃圾的风险回帖看帖。
这种实事求是的态度本身就是师道尊严所在。
同时,强烈鄙视那些不给任何答案,还站在技术道德制高点颐指气使说三道四的人。在
此就不点名批评了。

【在 p***o 的大作中提到】
: 没用过就是没用过啊, 通常这种static memeber直接就return new B了。
: 考虑到B()是可以用protected的A()来初始化基类的,我原以为access
: control这里就去掉了。谁知道基类和member的处理居然不一样 ...
: 看看标准再说。

JS
发帖数: 199
26
http://stackoverflow.com/questions/2393325/one-question-about-p
谁给个包子吧

【在 JS 的大作中提到】
: 红猪怎么变成思考猪了?
: factory pattern

z****e
发帖数: 2024
27
你想说啥?

【在 JS 的大作中提到】
: http://stackoverflow.com/questions/2393325/one-question-about-p
: 谁给个包子吧

JS
发帖数: 199
28
B

【在 z****e 的大作中提到】
: 你想说啥?
z****e
发帖数: 2024
29
哎,知八股者,红猪侠是也啊。。。。。。。。。。
红猪侠师傅,和我,关于什么是instance的讨论貌似有了结果。
如果subobject算是instance的话,只有C。

【在 JS 的大作中提到】
: B
G*****7
发帖数: 1759
30
fool. you failed at both getting help and understanding words.

【在 z****e 的大作中提到】
: 是啊,哪怕再简单的题贴出来都是有意义的。
: 即便是师傅,也难辨考虑不周。所以这些题目的讨论才富有乐趣和意义。
: 感谢师傅们百忙中冒着答案出错和被老婆骂不倒垃圾的风险回帖看帖。
: 这种实事求是的态度本身就是师道尊严所在。
: 同时,强烈鄙视那些不给任何答案,还站在技术道德制高点颐指气使说三道四的人。在
: 此就不点名批评了。

相关主题
C++ Q01: private inheritance.C++问题几个
how to initialize this struct.请教高手一个C++问题
C++ online Test 2题怎么把const T& 作为一个class的member
进入Programming版参与讨论
G*****7
发帖数: 1759
31
were you playing with compilers to confirm at last? told u so.

【在 z****e 的大作中提到】
: 智者千虑。。。
: 师傅还是师傅。
: 不过我刚看见你的代码的时候,非常惊叹于自己的无知,原来static能改变access。
: 犹豫了一下,没急着回帖,gcc一把,我靠,原来师傅也有诈和相公的时候啊。。。。

t****t
发帖数: 6806
32
自吹自擂的话就省省吧. 概念不清, 不会用C++的方法思考, 做再多的题也没用.

【在 z****e 的大作中提到】
: 是啊,哪怕再简单的题贴出来都是有意义的。
: 即便是师傅,也难辨考虑不周。所以这些题目的讨论才富有乐趣和意义。
: 感谢师傅们百忙中冒着答案出错和被老婆骂不倒垃圾的风险回帖看帖。
: 这种实事求是的态度本身就是师道尊严所在。
: 同时,强烈鄙视那些不给任何答案,还站在技术道德制高点颐指气使说三道四的人。在
: 此就不点名批评了。

z****e
发帖数: 2024
33
师傅一语中的。直接批判了现今市面上流行的面试题测试弊端,值得有关部门深刻反思
。避免人才培养和产业结构脱节的严重社会问题的发生。

【在 t****t 的大作中提到】
: 自吹自擂的话就省省吧. 概念不清, 不会用C++的方法思考, 做再多的题也没用.
n******t
发帖数: 4406
34
说实话,现在干这种事的2B公司还是挺多的。

【在 X****r 的大作中提到】
: C
: 你真的面试过一家公司问你这种题吗?反正我是没听说过。

b*******s
发帖数: 5216
35
C++ 11,貌似支持 using A::A;
m*********t
发帖数: 527
36
这个题不算什么八股偏门题吧。实现 singleton 用的不就是 private constructor 么
,还是有实际意义的。
b*******s
发帖数: 5216
37
private和protected还是不一样

【在 m*********t 的大作中提到】
: 这个题不算什么八股偏门题吧。实现 singleton 用的不就是 private constructor 么
: ,还是有实际意义的。

1 (共1页)
进入Programming版参与讨论
相关主题
弱问,上哪儿去找服务器?问一个java基础的初始化的问题,一直搞不明白
Global(static) variable initialization questionHow to make sure that I get the original object or only a copy (not original) in such situation?
C++ Q01: private inheritance.another c++ interview question
how to initialize this struct.[c++] static function in a class
C++ online Test 2题请教goodbug等大神几个AWS的问题
C++问题几个how to create an instance of base class in its derived class definition
请教高手一个C++问题[合集] C++ private member question
怎么把const T& 作为一个class的member请教C++面试题
相关话题的讨论汇总
话题: ensure话题: c++话题: class话题: instances话题: instance