期中理论题总结

程设理论期中总结

标签:c++


If we define double a = 3.14;,which is NOT correct? (B)

A.double &b = a;
B.int &b = a;
C.const int &b = a;
D.const double &b = a;

Which function will be called? (C)

void f(int i) {}
void f(const int i) {}

int main() {
  const int a = 0;
  f(a);
}

A.void f(int i)
B.void f(const int i)
C.compile error
D.runtime error

因为两个函数都是按值传递的参数,因此不会对main函数中的变量产生影响,编译器可能会认为是同一个函数,从而导致重复定义

Which function will be called? (B)

void f(int* i) {}
void f(const int* i) {}

int main() {

  const int a = 0;
  const int* p = &a;
  f(p);

}

A.void f(int* i)
B.void f(const int* i)
C.compile error
D.runtime error

这道题用的是指针传参,因此会对main函数里的变量产生影响。

Which of the following does the C++ compiler NOT examine, in order to select the proper overloaded? (D)

A. types of the arguments in the function call

B. order of the arguments in the function call

C. the number of arguments in the function call

D. the return type of the function

What does the code A a(); do ? (B)

class A {
  int i;
};

A. create a object named "a"
B. declare a function named "a"
C. compile error
D. runtime error

Which is correct? (A)

A. const object can only call const member function

B. non-const object can only call non-const member function

C. static member function can also be const

What‘s the value of a and b after constructor?

class A {
 public:
  A() : b(1), a(b+1) {}
 private:
  int a;
  int b;
};

A. 2 1
B. 1 2
C. undefined-value 1
D. undefined-value undefined-value

对象创建过程中跟定义的顺序有关,与参数列表的顺序无关

Which statement will cause a “compile error”? (3)

class A {
 public:
  A() : a(1) {}
 private:
  const int a;
};

int main() {
  A a, b; // (1)
  A c(a); // (2)
  a = b;  // (3)
  return 0;
}

The copy constructor is executed on :
(1) Assigned one object to another object at its creation
(2) When objects are sent to function using call by value mechanism
(3) When the function return an object

Which function will be called ? (D)

class A {
 public:
  void f() {}
  void f(int i) {}
};
class B : public A {
 public:
  void f(A a) {}
};

int main() {
  B b;
  b.f(3);
  return 0;
}

A. void f()
B. void f(int i)
C. void f(A a)
D. compile error

PS: Name hiding

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值