上一页 1 ··· 7 8 9 10 11 12 13 14 15 下一页
摘要: 静态变量 使用static 来定义变量,可以被全局的类使用,不需要声明就能调用,属于类成员,不属于对象成员 #include <iostream> using namespace std; class A{ public: //普通成员变量在构造时定义和初始化 A(int data = 0):m_d 阅读全文
posted @ 2020-05-10 21:34 c语言我的最爱 阅读(1117) 评论(0) 推荐(0) 编辑
摘要: 构造动态变量进行*m_pi = *that.m_pi /* 自定义的深拷贝 */ #include <iostream> using namespace std; class Integer{ public: Integer(int i) { m_pi = new int; //使用new int 阅读全文
posted @ 2020-04-02 19:28 c语言我的最爱 阅读(927) 评论(0) 推荐(0) 编辑
摘要: 使用析构函数,进行函数的删除 /* 析构函数 */ #include <iostream> using namespace std; class Integer { public: Integer(int i) { m_pi = new int; *m_pi = i; } ~Integer(void 阅读全文
posted @ 2020-04-02 19:16 c语言我的最爱 阅读(237) 评论(0) 推荐(0) 编辑
摘要: 使用const进行函数的定义 /* 使用const进行定义 */ #include <iostream> using namespace std; class A{ public: A(int i = 0):m_data(i) {} void print(void) const { //const表 阅读全文
posted @ 2020-04-02 19:12 c语言我的最爱 阅读(1309) 评论(0) 推荐(0) 编辑
摘要: 使用this可以用来表示当前类的变量 /* string 字符串 */ #include <iostream> #include <cstring> using namespace std; class String { public: String(const char* str) { m_str 阅读全文
posted @ 2020-04-02 18:37 c语言我的最爱 阅读(310) 评论(0) 推荐(0) 编辑
摘要: class和struct的区别就是class需要指明private 和 public 而 struct不需要 /* 类定义 */ #include <iostream> using namespace std; struct Student { public: void eat(const stri 阅读全文
posted @ 2020-03-31 11:03 c语言我的最爱 阅读(601) 评论(0) 推荐(0) 编辑
摘要: static_cast 表示静态变量的类型转换, 如int->char, 不合适的类型转换将会发生错误 /* static_cast 类型转换 */ #include <iostream> using namespace std; int main() { int* pi = NULL; //cha 阅读全文
posted @ 2020-03-31 11:02 c语言我的最爱 阅读(807) 评论(0) 推荐(0) 编辑
摘要: 对于变量而言, 左值可以使用 int& val = num; 对于常数而言,右值可以使用const int& val = num; 临时变量是右值 /* 左值 */ #include <iostream> using namespace std; int func(void) { int num = 阅读全文
posted @ 2020-03-30 15:41 c语言我的最爱 阅读(229) 评论(0) 推荐(0) 编辑
摘要: 使用& 表示reference可以用当前的值来表示原来的那个值, 数的地址保持不变 相较于a = b;相当于是进行赋值操作 /* & 表示引用 */ #include <iostream> using namespace std; int main(void) { int a = 10; int& 阅读全文
posted @ 2020-03-30 15:36 c语言我的最爱 阅读(434) 评论(0) 推荐(0) 编辑
摘要: 使用 int* pi = new int //申请动态变量, int* pi = new int(10) //直接进行申请 /* new动量申请 */ #include <iostream> using namespace std; int main() { int *pi = new int; * 阅读全文
posted @ 2020-03-30 15:29 c语言我的最爱 阅读(704) 评论(0) 推荐(0) 编辑
上一页 1 ··· 7 8 9 10 11 12 13 14 15 下一页