上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 29 下一页
摘要: 一、组合与继承 举例: 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) 编辑
摘要: Smart Pointer std::unique_ptr - single ownership std::shared_ptr - shared ownership std::weak_ptr - temp / no ownership 为什么使用智能指针? void bar(Entity* e) 阅读全文
posted @ 2020-10-14 17:55 朱果果 阅读(197) 评论(0) 推荐(0) 编辑
摘要: 举例:实现比较两个数的大小 #include <iostream> #include <string> using namespace std; #define GETMAX(a, b) ((a) > (b)) ? (a) : (b); inline int getMax(int a, int b) 阅读全文
posted @ 2020-10-14 16:21 朱果果 阅读(189) 评论(0) 推荐(0) 编辑
摘要: 一、作用域: 1.全局作用域 名字空间域(namespace) 2.局部作用域 块作用域 { ... } 3.类域 (class) 数据隐藏 int n = 1; int main(int argc, char const* argv[]) { int n = 2; { int n = 3; cou 阅读全文
posted @ 2020-10-14 15:43 朱果果 阅读(437) 评论(0) 推荐(0) 编辑
摘要: 举例:通过调用函数改变main函数里的变量的值 void foo(int m) { m = 8; } int main(int argc, char const* argv[]) { int n = 5; foo(n); return 0; } 可知,n的值不会被改变。 方法:使用指针 void f 阅读全文
posted @ 2020-10-14 14:39 朱果果 阅读(104) 评论(0) 推荐(0) 编辑
摘要: 举个例子: 1 #include <iostream> 2 #include <string> 3 using namespace std; 4 5 #define GETMAX(a, b) ((a) > (b) ? (a) : (b)) 6 7 int getMax(int a, int b) { 阅读全文
posted @ 2020-10-14 11:27 朱果果 阅读(267) 评论(0) 推荐(0) 编辑
摘要: 看一个例子:在C语言中实现圆面积计算 1 #include <stdio.h> 2 3 #define PI 3.14 4 5 int main(int argc, char const *argv[]) { 6 float r = 0.5; 7 float n = PI * r * r; 8 pr 阅读全文
posted @ 2020-10-14 10:55 朱果果 阅读(182) 评论(0) 推荐(0) 编辑
摘要: 先看几段代码: 1 string str1 ("aaaaaaaaaa"); 2 for(auto it1 = str1.begin(); it1 != str1.end() && !str1.empty(); ++it1 ) { 3 *it1 = toupper(*it1); 4 } 5 6 str 阅读全文
posted @ 2020-10-13 11:07 朱果果 阅读(947) 评论(0) 推荐(0) 编辑
摘要: 1、指针本身就是一个对象,允许指针之间的拷贝与赋值,可以在其生命周期内指向不同的对象。 引用并非对象,相反的,他是为一个已经存在的对象所起的别名。操作引用即操作对象。 2、指针无需在定义时初始化,而引用需要在定义时与初始值绑定。 int val = 1024; int &refval = val; 阅读全文
posted @ 2020-10-12 13:04 朱果果 阅读(212) 评论(0) 推荐(0) 编辑
上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 29 下一页