由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 问个先后的问题
相关主题
如何 initialize array member?template class instantiation问题
C++弱问a c++ question
c++ questionhow to prevent client programmer to pass by value?
const objectpointer to base class = new derived, what will happend??
关于C/C++里的Static variable的memory allocation/initializaC++问题
What does the default constructor do?[c++] 关于构造函数的一个小问题
几个C++书写风格疑问问个c++类的问题
为啥 const Base cb 要求Base() {} 而 const vBase vb 不呢?问个 ctor/copy ctor的问题
相关话题的讨论汇总
话题: ctor话题: class话题: why话题: first
进入Programming版参与讨论
1 (共1页)
j*****k
发帖数: 1198
1
class A{};
class B{};
class C: public A
{
C(){};
B b;
}
when instantiate C, C ctor first or B b first?
P********e
发帖数: 2610
2
A -> B -> C

【在 j*****k 的大作中提到】
: class A{};
: class B{};
: class C: public A
: {
: C(){};
: B b;
: }
: when instantiate C, C ctor first or B b first?

p***o
发帖数: 1252
3
Well, to be more accurate, aren't A's ctor and B's ctor called by C's ctor?

【在 P********e 的大作中提到】
: A -> B -> C
P********e
发帖数: 2610
4
A's ctor yes,
B's ctor no.

【在 p***o 的大作中提到】
: Well, to be more accurate, aren't A's ctor and B's ctor called by C's ctor?
p***o
发帖数: 1252
5

Why not? C() {} is C(): b() {} .

【在 P********e 的大作中提到】
: A's ctor yes,
: B's ctor no.

P********e
发帖数: 2610
6
Sure, you can explicitely write the code this way, then the answer change as
well
Just treat B as build-in type

【在 p***o 的大作中提到】
:
: Why not? C() {} is C(): b() {} .

p***o
发帖数: 1252
7
The answer should not change no matter how I write the code (well, there
is a difference, if you treat it as a difference, for build-in types and
PODs).
I mean if we are talking about the 'body' (inside {}) of those ctors, then
A->B->C is definitely correct. But I don't know if the interviewer really
want this anwser ...

as

【在 P********e 的大作中提到】
: Sure, you can explicitely write the code this way, then the answer change as
: well
: Just treat B as build-in type

P********e
发帖数: 2610
8
To anwser it correctly is enough, i checked thinking in c++, that's about it

【在 p***o 的大作中提到】
: The answer should not change no matter how I write the code (well, there
: is a difference, if you treat it as a difference, for build-in types and
: PODs).
: I mean if we are talking about the 'body' (inside {}) of those ctors, then
: A->B->C is definitely correct. But I don't know if the interviewer really
: want this anwser ...
:
: as

1 (共1页)
进入Programming版参与讨论
相关主题
问个 ctor/copy ctor的问题关于C/C++里的Static variable的memory allocation/initializa
问个c++问题What does the default constructor do?
template question几个C++书写风格疑问
问个 C++到C的问题为啥 const Base cb 要求Base() {} 而 const vBase vb 不呢?
如何 initialize array member?template class instantiation问题
C++弱问a c++ question
c++ questionhow to prevent client programmer to pass by value?
const objectpointer to base class = new derived, what will happend??
相关话题的讨论汇总
话题: ctor话题: class话题: why话题: first