C++
文章平均质量分 63
L_listen
这个作者很懒,什么都没留下…
展开
-
C++类中的this指针
1、类中this指针就是当前对象的地址(类成员函数的默认的第一个隐含参数)可以在下面的例子中得到结论#include typedef struct student{ char num[20]; char name[20]; int age;}*pstudent;void SetStudent(student* pf, char* num, char* name, int原创 2017-09-18 16:19:22 · 571 阅读 · 0 评论 -
String类简单实现
浅拷贝:也称位拷贝,编译器只是直接将指针的值拷贝过来,结果多个对象共用同一块内存,当一个对象将这块内存释放掉之后,另一些对象不知道该块空间已经还给了系统,以为还有效,所以在对这段内存进行操作的时候,发生了访问违规。深拷贝:为避免浅拷贝的问题,存在内存拷贝时开辟一块和被拷贝对象一样大小的空间并将其内存中的数据也拷贝到新开辟的内存中原创 2017-11-04 09:45:43 · 300 阅读 · 0 评论 -
小结多态
一、静态多态静态多态:编译器在编译期间完成的,编译器根据函数实参的类型(可能会进行隐式类型转换),可推断出要调用那个函数,如果有对应的函数就调用该函数,否则出现编译错误。#include using namespace std;int add(int right, int left){ return right + left;}float add(float r原创 2017-10-17 17:55:02 · 177 阅读 · 0 评论 -
继承小结
继承是复用代码的重要手段也为动态多态提供了平台 定义格式: 一、 继承关系 基类(父类) 派生类(子类) 派生类对象模型如图: 类 缺少继承权限:默认权限为private原创 2017-10-08 22:21:05 · 217 阅读 · 0 评论 -
模板小结
模板分为 函数模板 和 类模版泛型编程:编写与类型无关的逻辑代码,是代码复用的一种手段。模板是泛型编程的基础。函数模板 函数模板:代表了一个函数家族,该函数与类型无关,在使用时被参数化,根据实参类型产生函数的 特定类型版本。 模板函数的格式template<typename Param1, typename Param2,...,class Paramn> 返回值类型 函数名(参数列表){原创 2017-10-28 16:17:40 · 301 阅读 · 0 评论 -
list简单模拟实现
#define _CRT_SECURE_NO_WARNINGS#pragma once#include <assert.h>#include <iostream>using namespace std;template<class T>struct ListNode{ ListNode(const T& data = T()) :_pPre(0) , _pNex原创 2017-10-28 10:33:14 · 307 阅读 · 0 评论 -
Vector 简单模拟实现
Vector 简单模拟实现#define _CRT_SECURE_NO_WARNINGS#define _CRT_SECURE_NO_WARNINGS#pragma once#include <iostream>#include <assert.h>using namespace std;struct _TrueType // 实现类型萃取{ bool Get()原创 2017-10-28 10:19:46 · 293 阅读 · 0 评论 -
c++日期类
#include using namespace std;class Date{public: Date(int year = 2017, int month = 9, int day = 20) : _year(year) , _month(month) , _day(day) {} Date& operator=(const Date& d); // 前置++原创 2017-09-21 19:31:56 · 252 阅读 · 0 评论 -
复数类 运算符重载
#includeusing namespace std;class Complex{public: friend ostream& operator<<(ostream& _cout, Complex c); //输出函数需要访问私有成员,声明为友元函数 Complex(double real = 0.0, double image = 0.0); Comple原创 2017-09-14 21:11:51 · 717 阅读 · 0 评论 -
二叉树的相关操作
C++实现二叉树原创 2017-12-05 22:51:05 · 287 阅读 · 0 评论