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

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

  };

  int main()

  {

  A a(1,2,3);

  }

第 1 种写法是错误的,第 2 种正确。

4.考察拷贝构造函数和赋值的区别。

  class A

  {

  public:

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

  A(const A& a) { cout<<"consttuct A by copy"<

  A& operator =(const A& a) { cout<<"cosnt A by operator ="<

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

  };

  int main()

  {

  A a;

  A b=a; //调用拷贝构造函数

  A c(a); //调用拷贝构造

  A d;

  d=a; //赋值

  }

  输出:

  Construct A by default //构造对象 a

  consttuct A by copy //拷贝构造 b

  consttuct A by copy //拷贝构造 c

  Construct A by default //构造 a

  cosnt A by operator = //赋值 d=a

  Destruct A

  Destruct A

  Destruct A

  Destruct A

5.考察函数指针

  voidfunc(char* a)

  {

  cout<

  }

  int main()

  {

相关推荐

猜你喜欢

大家正在看

换一换