1 类的定义 2 对象的定义 3 对象的使用 4 构造函数 5 析构函数 6 对象数组的定义与使用 7 对象指针,this指针 8 友元 选择题:1 若有下面的函数调用: fun(a+b,3,max(n-1,b)) 则fun的实参个数是( )。 A 3 B 4 C 5 D 6 选择题:2 编译运行这个程序将出现的情况是( )。 A 编译出错 无法运行 B 输出:3 C 输出3.0 D 输出一个不确定的数 选择题:3 有如下函数定义: void func(int a, int b) {a++; b++;} 若执行代码段: int x=0,y=1; func(x,y); 则变量x和y的值分别是( ) A 0和1 B 1和1 C 0和2 D 1和2 选择题:5 (通过本题理解什么时候需要深拷贝) #includecstring #includeiostream using namespace std; class MyString { public: MyString(const char* s); ~MyString() {delete []data;} private: unsigned len; char *data; }; 选择题:9 (通过本题知道:析构的顺序和构造相反) #includeiostream #includeiomanip using namespace std; class MyClass { public: MyClass( ){cout‘A’;} MyClass(char c ){coutc;} ~MyClass() {cout‘B’;} }; 选择题:10 #includeiostream using namespace std; class test { private: int a; public: test( ){cout“constructorendl”;} test(int a){coutaendl;} test(const test _test) {a=_test.a; cout“copy constructor”endl;} ~test() {cout“destructor”endl;} }; 填空题:2 (通过本题学会:读程——从main开始) #includeiostream using namespace std; class Con { char ID; public: Con( ):ID(‘A’) {cout1;} Con(char ID ):ID(ID) {cout2;} Con(Con c):ID(c.getID()) {cout3;} char getID() const {return ID;} }; void show(Con c) {coutc.getID();} 填空题:6 (通过本题巩固:析构的顺序和构造相反) #includeiostream using namespace std; class A{ public: A( ) {cout“A”;} ~A( ) {cout“A”;} }; class B{ A a; public: B( ) {cout“B”;} ~B( ) {cout“B”;} }; 填空题:7 #includeiostream using namespace std; void fun(float* a, float* b) { float w; *a=*a+*a; w=*a; *a=*b; *b=w; } 填空题:8 (通过本题学习:填程——读懂程序思路) * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 自测题: 下列各类函数中, ( )不是类的成员函数。 A 析构函数 B 友元函数 C 构造函数 D 拷贝构造函数 当希望一个类可以访问另一个类的私有成员时,也可以将该类声明为另一个类的友元类。 友元类的所有成员函数可以被视为该类的友元函数,能够访问该类的私有成员和保护成员。 友元类 class A{ ..... friend class B; } class B{ ..... } 类B
您可能关注的文档
最近下载
- DB11∕T 2422-2025 公路隧道空气净化系统设计规范.pdf VIP
- 11ZJ501内墙装修及配件(中南-4).docx VIP
- 太阳能跨季节储热技术.pdf
- HG_T 20679-2014 化工设备、管道外防腐设计规范(附条文说明).docx
- 南部标准图集21ZJ501内墙装修及配件内墙装修及配件.pdf VIP
- 17ZJ112 建筑外墙防水构造.pdf VIP
- 建筑图集5(2021)_11ZJ951_漏花 .docx VIP
- 5-中南标11ZJ902-11ZJ903-11ZJ951-标准图集.docx VIP
- 2024-2025学年湖北省襄阳市襄州区八年级上册期末数学试卷含答案.pdf VIP
- 98ZJ411 阳台、外廊栏杆.pdf VIP
原创力文档

文档评论(0)