程设理论期中总结
标签: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