摘要: 1.作用:无法修改数据成员,一般用来修饰Get的函数 2.本质:this指针类型:const T* const 3.意义:让编译器提醒开发者该函数不能修改类的成员变量,用于const对象(引用或指针) 看一个例子: 1 #include <iostream> 2 #include <string> 阅读全文
posted @ 2020-10-15 18:48 朱果果 阅读(728) 评论(0) 推荐(0) 编辑
摘要: 在 C++ 中,每一个对象都能通过 this 指针来访问自己的地址。this 指针是所有成员函数的隐含参数。因此,在成员函数内部,它可以用来指向调用对象。 友元函数没有 this 指针,因为友元不是类的成员。只有成员函数才有 this 指针。 成员函数最终被编译成与对象无关的普通函数,除了成员变量, 阅读全文
posted @ 2020-10-15 18:36 朱果果 阅读(112) 评论(0) 推荐(0) 编辑
摘要: 函数重载 函数名相同 参数列表(个数/类型/顺序)不同 相同作用域 函数重载不考虑返回值的不同 函数隐藏 作用域不同 函数名相同 参数和返回值不考虑 函数覆盖(虚函数) 作用域不同(父子类之间的继承关系) 函数名,参数列表(参数个数/顺序/类型),返回值,调用约定必须相同 有virtual关键字 看 阅读全文
posted @ 2020-10-15 17:40 朱果果 阅读(1110) 评论(0) 推荐(0) 编辑
摘要: 举例: 在一个聊天室里,有一群人,每个人都会说自己的话 使用一个结构把一群人表达出来 #include <stdlib.h> #include <iostream> #include <string> using namespace std; class CPerson { public: CPer 阅读全文
posted @ 2020-10-15 12:28 朱果果 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 一、组合与继承 举例: 1 #include <iostream> 2 3 class CPerson { 4 public: 5 CPerson() {} 6 ~CPerson() {} 7 //获取性别 8 int GetGender() { 9 return m_nGender; 10 } 1 阅读全文
posted @ 2020-10-15 10:23 朱果果 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 举个🌰 #include <stdlib.h> #include <iostream> #include <string> using namespace std; class CStudent { public: CStudent() { cout << "CStudent()\r\n"; } 阅读全文
posted @ 2020-10-15 09:12 朱果果 阅读(124) 评论(0) 推荐(0) 编辑