学习日记
98年爱吃茶叶蛋
这个作者很懒,什么都没留下…
展开
-
C语言版动态数组1
#include <malloc.h> #include <stdio.h> #include <string> //创建C的结构体 struct Dynamic_Array { int* Array_Header; //数组头 unsigned int Array_Cap; //数组容量 unsigned int Array_Num; //数组元素数量 }; void Initializaton(struct Dynamic_Array* P_Array) {原创 2021-09-24 15:29:12 · 49 阅读 · 0 评论 -
C++虚基类的底层原理
相当于继承了两个虚基类指针 Virtual Base Pointer,指针结合偏移量分别指向父类 如VBptr1的起始为0,加上偏移量8指向父类为8 VBptr2的起始为4,加上偏移量4同样为8 #include <iostream> using namespace std; class Animal { public: int m_Age; }; //虚继承 class Sheep : virtual public Animal{}; class Tuo : virtual pub原创 2021-08-26 16:38:18 · 312 阅读 · 0 评论 -
查看类中的内存大小
在采用继承时,当子类继承父类时,遇到同名的属性或函数时,父类中的属性或函数需要多做一步处理 #include <iostream> #include <string> using namespace std; //基类 class Base { public: static int m_A; //静态变量类内声明 static void func() { cout << "Base - static void func()" << endl;原创 2021-08-25 19:46:31 · 176 阅读 · 0 评论 -
运算符重载
C++中通过运算符重载实现对对象的一些运算符操作 加号运算符重载 #include<iostream> #include <string> using namespace std; class Person { public: int m_A; int m_B; public: //列表初始化 Person() {}; Person(int a,int b) { this->m_A = a; this->m_B = b; } //加号运算符重载原创 2021-06-17 10:53:32 · 67 阅读 · 0 评论 -
this指针
this指针 this指针是隐含每一个非静态成员函数内的一种指针 this指针不需要定义,直接使用即可,应用场景: 当形参和成员变量同名时,可用this指针来区分 类的非静态成员函数中返回对象本身,return *this #include<iostream> #include <string> using namespace std; class Person { public: Person(int age) { //当重名时用this指针来区分原创 2021-06-07 20:15:11 · 44 阅读 · 0 评论 -
静态成员函数
静态成员函数 静态成员变量特点: 在编译阶段分配内存 类内声明,类外初始化 所有对象共享同一份数据 #include<iostream> #include <string> using namespace std; class Person { public: static void fun1() { m_A = 100; cout << "静态成员函数static void fun1的调用 " << endl; } int m_B原创 2021-06-07 15:43:12 · 43 阅读 · 0 评论 -
深拷贝与浅拷贝
深拷贝与浅拷贝 程序默认情况下会自带浅拷贝,但是在对指针的拷贝时,在之后的析构环节容易引发重复清除堆区而导致程序崩溃。因此采用深拷贝来为指针重新申请一段堆区。 #include <iostream> #include <string> using namespace std; class Person { public: //默认构造函数 Person() { cout << "Person类的默认构造函数" << endl; } //有参构造原创 2021-06-05 17:22:38 · 58 阅读 · 0 评论