由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - C++ Q60 calling virtual function in constructor (JPMorgan)
相关主题
C++ online Test 一题Bloomberg网上测试题
c++ vs Java virtual 实现(Y家)包子呼唤大牛--问关于C++Destructor的问题 (转载)
问几个跟C++有关的面试题刚phone完MS,好紧张。。。。
贡献点g家电面题问几道面试中遇到的C++问题
发发面经 攒人品 C++的C++ online Test 一题
A question about C++. Thanks.今天的电面 - developer position
Qualcomm Phone Interbview面筋,赚RPC++ Question
新Qualcomm面经请问这个C++问题对吗?
相关话题的讨论汇总
话题: virtual话题: cout话题: class话题: public
进入JobHunting版参与讨论
1 (共1页)
c**********e
发帖数: 2007
1
#include
using namespace std;
class A {
public:
A() { cout<<"A_constructor "; f(); }
virtual void f() { cout<<"A_f "; }
};
class B: public A {
public:
B() { cout<<"B_constructor "; f(); }
virtual void f() { cout<<"B_f"; }
};
int main()
{ B b; }
What is the output?
a) A_constructor A_f B_constructor A_f
b) A_constructor A_f B_constructor B_f
c) Cannot call f() in A's constructor
d) None of above.
d********t
发帖数: 9628
2
b
q**r
发帖数: 611
3
怎么derived class也用virtual啊? 隐约记得constructor不能用virtual的, 估计
又记错了
c**********e
发帖数: 2007
4
The word virtual in derived class does not matter. The derived class
function is virtual if the base class member function is virtual.

【在 q**r 的大作中提到】
: 怎么derived class也用virtual啊? 隐约记得constructor不能用virtual的, 估计
: 又记错了

c**********e
发帖数: 2007
5
The question is pretty interesting, because the object is not constructed
yet when the member function is called.
Therefore, there is a question which f() the call f() in the constructor of
derived class call?
1 (共1页)
进入JobHunting版参与讨论
相关主题
请问这个C++问题对吗?发发面经 攒人品 C++的
C++ Q47: protected constructor (C39)A question about C++. Thanks.
发两个软件组的面试题Qualcomm Phone Interbview面筋,赚RP
a c++ interview question新Qualcomm面经
C++ online Test 一题Bloomberg网上测试题
c++ vs Java virtual 实现(Y家)包子呼唤大牛--问关于C++Destructor的问题 (转载)
问几个跟C++有关的面试题刚phone完MS,好紧张。。。。
贡献点g家电面题问几道面试中遇到的C++问题
相关话题的讨论汇总
话题: virtual话题: cout话题: class话题: public