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

招聘笔试题2018-11-22才子老师

  A is speaking!

  Destruct D

  Destruct C

  Destruct B

  Destruct A

2.考察非虚析构函数这道题

  class Parent

  {

  public:

  Parent(){cout<<"Parent construct"<

  ~Parent(){ cout<<"Parent destruct "<

  };

  class Child : public Parent

  {

  public:

  Child() { cout<<"Child construct "<

  ~Child() {cout<<"child destruct"<

  };

  int main()

  {

  Parent *p;

  Child *c = new Child();

  p = c;

  delete p; // 因为析构函数是非 virtual 的,故析构的时候按照指针的类型进行析构

  }

  输出:

  Parent construct

  Child Construct

  Parent destruct

3.考察初始化列表的写法

  class A

  {

  public:

  A(int x, int y, int z):a=x,b=y,c=z {} (1)

  A(int x, int y, int z):a(x),b(y),c(z){} (2)

  private:

  int a;

  int b;

  int c;

相关推荐

猜你喜欢

大家正在看

换一换