随笔分类 - C++学习不完全笔记
摘要:点击查看代码 #include<iostream> #include<string> using namespace std; //占位参数 //返回值类型 函数名(数据类型){} //目前阶段的占位参数我们还用不到,后面课程中会用到 void func(int a, int){ cout << "
阅读全文
摘要:点击查看代码 #include<iostream> #include<string> using namespace std; //函数默认参数 //如果我们自己传入数据,就用自己的数据,如果没有,那么用默认值 //注意事项 //1、如果某个位置已经有了默认参数,那么从这个位置往后,从左到右都必须有
阅读全文
摘要:防止误操作 点击查看代码 #include<iostream> #include<string> using namespace std; //常量引用 //使用场景:用来修饰形参,防止误操作 //打印函数 void showValue(int &val) { //原名b指向的数据也变成1000了(
阅读全文
摘要:引用做函数参数 总结:通过引用参数产生的效果同按地址传递是一样的。引用的语法更清楚简单 点击查看代码 #include<iostream> #include<string> using namespace std; //交换函数 //1、值传递 (形参不会修饰实参) void mySwap01(in
阅读全文
摘要:引用 别名和原名操作同一块内存 引用注意事项 点击查看代码 #include<iostream> #include<string> using namespace std; int main() { int a = 10; //1、引用必须初始化 //int &b; //错误,必须初始化 int &
阅读全文
摘要:new操作符 new基本语法 利用new在堆区中开辟一个数组,在堆区中开辟一段连续的内存空间 点击查看代码 #include<iostream> #include<string> using namespace std; //1、new的基本语法 int* func() { //在堆区创建一个整型数
阅读全文
摘要:栈区 点击查看代码 #include<iostream> #include<string> using namespace std; //栈区数据注意事项 -- 不要返回局部变量的地址 //栈区的数据由编译器管理开辟和释放 //形参数据也会放在栈区 int* func() { int a = 10;
阅读全文
摘要:注意: (1)代码区和全局区都是程序在运行前划分好的两个区域,程序运行后才会有栈区和堆区 (2)常量区包括 字符串常量 和 其他常量,其他常量是指,用const修饰的一些变量 点击查看代码 #include<iostream> #include<string> using namespace std
阅读全文
摘要:构造函数调用规则 1、创建一个类,C++编译器会给每个类都添加至少3个函数 (1)默认构造 (空实现) (2)析构函数(空实现) (3)拷贝构逍(值拷贝) 点击查看代码 #include<iostream> #include<string> using namespace std; //构造函数的调
阅读全文
摘要:拷贝构造函数调用时机 点击查看代码 #include<iostream> #include<string> using namespace std; //拷贝构造函数调用时机 //1、使用一个已经创建完毕的对象来初始化一个新对象 //2、值传递的方式给函数参数传值 //3、值方式返回局部对象 cla
阅读全文
摘要:值传递 点击查看代码 #include<iostream> #include<string> using namespace std; //值传递 //定义函数,实现两个数字进行交换函数 void swap(int num1, int num2) { cout << "交换前:" << endl;
阅读全文
摘要:函数的调用 总结:函数定义里小括号内称为形参,函数调用时传入的参数称为实参 点击查看代码 #include<iostream> #include<string> using namespace std; //定义一个加法函数 //函数定义的时候,num1和num2并没有真实数据,他只是一个形式上的参
阅读全文
摘要:构造函数的分类及调用 点击查看代码 #include<iostream> #include<string> using namespace std; //构造函数的分类及调用 //分类 //按照参数分类 无参构造(默认构造) 和 有参构造 //按照类型分类 普通构造 和 拷贝构造 class Per
阅读全文
摘要:对象的初始化和清理(强制要求) 点击查看代码 #include<iostream> #include<string> using namespace std; //对象的初始化和清理 class Person { public: //1、构造函数 //没有返回值 也不用写void //函数名与类名相
阅读全文
摘要:在类中我们可以让另一个类作为本类的成员 注意本节课学习在头文件和源文件中的声明(105节) 点击查看代码 #include<iostream> #include<string> using namespace std; //点和圆的关系案例 //点类 class Point { public: //
阅读全文
摘要:判断两个立方体是否相等 #include<iostream> #include<string> using namespace std; //立方体类设计 //1、创建立方体类 //2、设计属性 //3、设计行为获取立方体面积和体积 //4、分别利用全局函数和成员函数判断两个立方体是否相等 clas
阅读全文
摘要:成员属性私有化设置 点击查看代码 #include<iostream> #include<string> using namespace std; //成员属性设置为私有 //1、可以自己控制读写权限 (提供接口) //2、对于写可以检测数据的有效性 class Person { public: /
阅读全文
摘要:class和struct的区别 点击查看代码 #include<iostream> #include<string> using namespace std; //struct和class区别 //struct 默认权限是 公共public //class 默认权限是 私有private class
阅读全文
摘要:封装意义 点击查看代码 #include<iostream> #include<string> using namespace std; //访问权限 //三种 //公共权限(public) 成员类内可以访问 类外可以访问 //保护权限(protected) 成员类内可以访问 类外不可以访问(继承性
阅读全文

浙公网安备 33010602011771号