c+练习题
1. 识认性 encapsulation、多态性polymorphic 继承性inherited OOP语言特点
2. Assume that AB is a class, the declaration of copy constructor of that class should be ( )。
(A)AB&(AB x) (B)AB(AB x) (C)AB(AB &x) (D)AB(AB *x)
当用已存在的对象创建新对象时候,编译器会自动调用拷贝构造函数完成新对象的初始化操作。
假设该代码是成立,在值传递时候,传参期间会产生一个临时变量,当我们实例化对象d1后,将d1拷贝给d2时调用拷贝构造函数,此时d1发生值传递,d1将值传递给临时对象dd1,而此时又要调用拷贝构造函数将d1的值传递给dd1,因为是值传递,一旦调用又要产生临时变量ddd1,将d1的值传递给临时变量ddd1,那么问题就很明显了,值传递,会进行形参实例化,类类型实例化,会再调用构造函数,就会一直调用,因此结果就是无穷递归
3 For the member of a structure, the default access modifier is ( )。
(A) public; (B) private; (C) protected; (D) static; class-> private
4. Assume AB is a class, to execute statement “AB a(4),b[3],*p[2];”, how many times to invoke the constructor?( )。
(A) 3 (B) 4 (C) 6 (D) 9 a(4)调用自定义构造函数一次 b调用无参数构造函数3次 p不调用
5 函数的默认返回值是undefined 而构造函数没有返回值
6. Parameterized stream manipulator setfill specifies the fill character that is displayed when an output is displayed in a field wider than the number of characters or digits in the output. The effect of setfill applies:
(A) Only to the current value being displayed.
(B) Only to outputs displayed in the current statement.
(C) Until explicitly set to a different setting.
(D) Until the output buffer is flushed. 然而 一起使用的setw只对 下次一输出的值<<a<<b也仅对a有作用
Treating a bass-class object as a derived-class object can cause errors. true
Operator dynamic-cast can be used to downcast base-class pointers safely true
多态分为运行时多态与编译时多态 其中 if switch 虚函数 都是运行时多态 函数重载属于编译时多态
9. 一个类模板定义了静态数据成员,则( A )。
A.每一个实例化的模板类都有一个自己的静态数据成员。
B.每一个实例化的对象都有一个自己的静态数据成员。
C.它的类型必须是类模板定义的抽象类型。
D.所有模板类的对象公享一个静态数据成员。
10 每一次形参都会调用一个复制构造函数来传递对象并析构函数,所以参数应当是引用 但你可以自己写复制构造函数
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步