随笔分类 -  C++学习笔记

摘要:1.什么是函数模版 函数模板,实际上是建立一个通用函数,其函数类型和形参类型不具体制定,用一个虚拟的类型来代表。这个通用函数就成为函数模板 2.怎么编写函数模版 //T代表泛型的数据类型,不是只能写T, template<class T>//让编译器看到这句话后面紧跟着的函数里有T不要报错 void 阅读全文
posted @ 2023-02-10 19:16 CodeMagicianT 阅读(77) 评论(0) 推荐(0) 编辑
摘要:C++提供了函数模板(function template)。所谓函数模板,**实际上是建立一个通用函数,其函数类型和形参类型不具体制定,用一个虚拟的类型来代表。这个通用函数就成为函数模板。**凡是函数体相同的函数都可以用这个模板代替,不必定义多个函数,只需在模板中定义一次即可。在调用函数时系统会根据 阅读全文
posted @ 2023-02-10 15:52 CodeMagicianT 阅读(20) 评论(0) 推荐(0) 编辑
摘要:#define _CRT_SECURE_NO_WARNINGS #include<iostream> using namespace std; //值传递 void swap(int a, int b) { int tmp = a; a = b; b = tmp; } //指针传递 void swa 阅读全文
posted @ 2023-02-09 15:37 CodeMagicianT 阅读(34) 评论(0) 推荐(0) 编辑
摘要:1.cin 用法1:最基本,也是最常用的用法,输入一个数字: #pragma warning(disable:4996) #define _CRT_SECURE_NO_WARNINGS 1 #include <iostream> using namespace std; int main() { i 阅读全文
posted @ 2023-02-07 14:30 CodeMagicianT 阅读(55) 评论(0) 推荐(0) 编辑
摘要:**左值参数是可以被引用的数据对象。**例如,变量、数组元素、结构成员、引用和接触引用的指针。非左值包括字面常量(用引号括起的字符串除外,他们由其它地址表示)和包括多项的表达式。在C语言中左值最初是可出现在赋值语句左边的实体,但这是引入关键字const之前的情况。现在,常规变量和const变量都可视 阅读全文
posted @ 2023-01-08 16:46 CodeMagicianT 阅读(31) 评论(0) 推荐(0) 编辑
摘要:1.动态联编和静态联编(重点难点) 1.静态联编 编译器会根据函数调用的对象类型,在编译阶段就确定函数的调用地址,这就是静态联编(早绑定) 2.虚函数 在普通成员函数前面加virtual,该函数变为虚函数,是告诉编译器这个函数要晚绑定 3.动态联编 在运行阶段才确定调用哪个函数(晚绑定), 4.动态 阅读全文
posted @ 2022-10-17 22:00 CodeMagicianT 阅读(62) 评论(0) 推荐(0) 编辑
摘要:1.多继承概念 我们可以从一个类继承,我们也可以能同时从多个类继承,这就是多继承。但是由于多继承是非常受争议的,从多个类继承可能会导致函数、变量等同名导致较多的歧义。 class Base1{ public: void func1(){ cout << "Base1::func1" << endl; 阅读全文
posted @ 2022-10-16 21:32 CodeMagicianT 阅读(48) 评论(0) 推荐(0) 编辑
摘要:1.继承中的对象模型 在C++编译器的内部可以理解为结构体,子类是由父类成员叠加子类新成员而成: class Aclass{ public: int mA; int mB; }; class Bclass : public Aclass{ public: int mC; }; class Cclas 阅读全文
posted @ 2022-10-16 21:31 CodeMagicianT 阅读(48) 评论(0) 推荐(0) 编辑
摘要:程序: #pragma warning(disable:4996) #define _CRT_SECURE_NO_WARNINGS 1 //2022年10月15日20:24:40 #include <iostream> using namespace std; class Father { publ 阅读全文
posted @ 2022-10-15 21:05 CodeMagicianT 阅读(30) 评论(0) 推荐(0) 编辑
摘要:1.为什么要有继承 //网页类 class IndexPage{ public: //网页头部 void Header(){ cout << "网页头部!" << endl; } //网页左侧菜单 void LeftNavigation(){ cout << "左侧导航菜单!" << endl; } 阅读全文
posted @ 2022-10-15 20:09 CodeMagicianT 阅读(39) 评论(0) 推荐(0) 编辑
摘要:字符串类.cpp #pragma warning(disable:4996) #define _CRT_SECURE_NO_WARNINGS 1 //2022年10月14日21:22:09 #include<iostream> using namespace std; #include "MyStr 阅读全文
posted @ 2022-10-15 18:56 CodeMagicianT 阅读(23) 评论(0) 推荐(0) 编辑
摘要:程序1: #pragma warning(disable:4996) #include <iostream> using namespace std; class Maker { public: Maker() { a = 0; } void SetA(int val) { a = val; } / 阅读全文
posted @ 2022-10-15 18:56 CodeMagicianT 阅读(20) 评论(0) 推荐(0) 编辑
摘要:1.类里有重载函数调用符号的类实例化的对象也叫仿函数 2.仿函数的作用:1.方便代码维护 2.方便有权限的调用函数。3.作为算法的策略 程序1: #pragma warning(disable:4996) #include <iostream> using namespace std; class 阅读全文
posted @ 2022-10-14 20:13 CodeMagicianT 阅读(20) 评论(0) 推荐(0) 编辑
摘要:1.智能指针类是管理另一个类的对象的释放 class Maker { public: Maker() { cout << "无参构造" << endl; } void printMaker() { cout << "hello Maker" << endl; } ~Maker() { cout << 阅读全文
posted @ 2022-10-14 18:50 CodeMagicianT 阅读(26) 评论(0) 推荐(0) 编辑
摘要:程序1: 11数组下标重载.cpp #pragma warning(disable:4996) #include <iostream> using namespace std; #include "MyArray.h" void test() { MyArray arr; for( int i = 阅读全文
posted @ 2022-10-13 20:40 CodeMagicianT 阅读(22) 评论(0) 推荐(0) 编辑
摘要:1.前置和后置(++/--)运算符重载 重载的++和--运算符有点让人不知所措,因为我们总是希望能根据它们出现在所作用对象的前面还是后面来调用不同的函数。解决办法很简单,例如当编译器看到++a(前置++),它就调用operator++(a),当编译器看到a++(后置++),它就会去调用operato 阅读全文
posted @ 2022-10-13 14:32 CodeMagicianT 阅读(42) 评论(0) 推荐(0) 编辑
摘要:程序1: #pragma warning(disable:4996) //2022年10月12日21:26:43 #include <iostream> using namespace std; class Maker { public: Maker() { id = 0; age = 0; } M 阅读全文
posted @ 2022-10-12 21:38 CodeMagicianT 阅读(19) 评论(0) 推荐(0) 编辑
摘要:1.赋值(=)运算符重载 赋值符常常初学者的混淆。这是毫无疑问的,因为’=’在编程中是最基本的运算符,可以进行赋值操作,也能引起拷贝构造函数的调用。 class Person{ friend ostream& operator<<(ostream& os,const Person& person){ 阅读全文
posted @ 2022-10-12 21:04 CodeMagicianT 阅读(48) 评论(0) 推荐(0) 编辑
摘要:1.视频内容 程序1: #pragma warning(disable:4996) #include <iostream> using namespace std; void test() { int a; cin >> a; cout << a << endl; } class Maker { f 阅读全文
posted @ 2022-10-05 22:23 CodeMagicianT 阅读(33) 评论(0) 推荐(0) 编辑
摘要:1.视频内容 程序1: #pragma warning(disable:4996) //2022年10月5日21:11:12 #include <iostream> using namespace std; class Maker { public: Maker(int id, string nam 阅读全文
posted @ 2022-10-05 22:22 CodeMagicianT 阅读(45) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示