c++学习15 -- 类

摘要: 定义:具有相同属性的行为的对象的集合(人类,就是一个集合;小明,就是一个具体个体,或者叫对象) 类的所有成员(个别特殊的static),必须通过对象访问。 阅读全文
posted @ 2018-05-11 15:17 theslowman 阅读(87) 评论(0) 推荐(0) 编辑

c++学习14 -- 预处理

摘要: //防止头文件重复包含 //通用,利用c语言、c++语法的规范 #ifndef AAA #define AAA #endif //取决于编译器,有的编译器有的支持,有的不支持。移植性不太好 #pragma once 阅读全文
posted @ 2018-05-11 15:01 theslowman 阅读(86) 评论(0) 推荐(0) 编辑

c++学习13 -- 函数

摘要: 函数重载 阅读全文
posted @ 2018-04-28 11:42 theslowman 阅读(122) 评论(0) 推荐(0) 编辑

c++学习12 -- for循环

摘要: #include using namespace std; int main() { int i = 0; for(i = 0;i<5;i++) { cout << i << endl; } system("pause"); return 0; } 阅读全文
posted @ 2018-04-28 11:26 theslowman 阅读(167) 评论(0) 推荐(0) 编辑

c++学习11 -- 引用返回值

摘要: #include using namespace std; // 引用局部变量,操作的是非法空间,结果是未知的。 int &fun() { int a = 12; return a; } int main() { int &b = fun(); //语句执行完了之后,函数内的变量a会释放。 cout << b << endl; //因此b现在引用的是一个... 阅读全文
posted @ 2018-04-27 17:09 theslowman 阅读(201) 评论(0) 推荐(0) 编辑

c++学习10 -- 交换

摘要: #include using namespace std; //利用引用是相同空间实现 void ExChange(int &a1 , int &b1) { int nTemp = a1; a1 = b1; b1 = nTemp; } //不引用的话,新变量有自己的空间,不会交换数据。 void notExChange(int a1 , int b1) { ... 阅读全文
posted @ 2018-04-27 16:53 theslowman 阅读(114) 评论(0) 推荐(0) 编辑

c++学习9 -- 引用于函数

摘要: 通过引用可以改变函数外面的值 阅读全文
posted @ 2018-04-27 16:18 theslowman 阅读(108) 评论(0) 推荐(0) 编辑

c++学习8 -- 引用变量

摘要: #include using namespace std; int main() { //给变量取别名 int a = 12; int &c = a; //声明变量a的一个引用 c, c是变量a的一个别名,不在是上节中的去地址符。同一个变量可以多个引用。 //引用声明的时候必须要初始化, 不允许出现 int &d; int d = c; //... 阅读全文
posted @ 2018-04-27 16:04 theslowman 阅读(124) 评论(0) 推荐(0) 编辑

c++学习7 -- 指针,空间的申请与释放

摘要: #include using namespace std; int main() { //new 申请空间 //int *p = (int*)malloc(sizeof(int)); //c语言的申请用法 int *p1 = new int; //new + type 类型需要匹配 int *p2 = new int(121); //初始化一个值 ... 阅读全文
posted @ 2018-04-27 15:25 theslowman 阅读(3746) 评论(0) 推荐(0) 编辑

c++学习6 -- 结构体

摘要: #include using namespace std; struct Node { int m; void fun() { printf ("hello c++"); } }; int main() { Node a; a.fun(); system("pause"); return 0; } //c++... 阅读全文
posted @ 2018-04-26 17:35 theslowman 阅读(87) 评论(0) 推荐(0) 编辑