艾默生软件工程师笔试题和面试题答案

招聘笔试题2018-11-22李一老师

1.考察虚继承内存体系

  class A

  {

  public:

  A() { cout<<"Construct A"<

  ~A() { cout<<"Destruct A"<

  void speak() { cout<<"A is speaking!"<

  };

  class B:public virtual A

  {

  public:

  B() { cout<<"Construct B"<

  ~B() { cout<<"Destruct B"<

  };

  class C:public virtual A

  {

  public:

  C() { cout<<"Constuct C"<

  ~C() { cout<<"Destruct C"<

  };

  class D:public B, public C

  {

  public:

  D(){ cout<<"Constsruct D"<

  ~D(){ cout<<"Destruct D"<

  };

  int main()

  {

  D *p = new D();

  p->speak();

  delete p;

  }

  输出:

  Construct A

  Construct B

  Constuct C

  Constsruct D

相关推荐

猜你喜欢

大家正在看

换一换