C++
Cycleche
这个作者很懒,什么都没留下…
展开
-
C++入门
#include <iostream>using namespace std;int main(){ cout << "21天精通C++" << endl; operator<<(cout, "一年熟悉C++\n"); [](const char* str = "三年用过C++"){cout << str << endl;}(); return 0;}...原创 2020-08-25 18:05:41 · 131 阅读 · 0 评论 -
C++ 对象地址解析
C++中,实例化一个对象,表示请求编译器分配一块固定大小的内存,大小为sizeof(object),那么问题来了,这个对象的地址&object是什么呢?从6个方面考虑对象地址:1、普通类class中包含了成员函数和成员变量,对象object的地址即为该对象内所包含的第一个字段的地址。 这个没啥好说的,类似数组地址与数组首元素地址、结构体变量的地址与第一个字段的地址。#include <iostream>#include <string>using n...原创 2020-08-25 18:31:21 · 5189 阅读 · 1 评论 -
C++ 选择排序
代码如下:// Example program#include <iostream>#include <string>#include <algorithm>using namespace std;void swap(int& a, int& b){ int tmp = a; a = b; b = tmp;}int selectSort(int* arr, int len){ if(NULL =原创 2020-08-05 15:21:08 · 290 阅读 · 3 评论 -
C++ 多态性之向下转型
1、使用dynamic_cast<T>expression 执行向下转型后,调用派生类新增的函数PrintVersion();2、将基类对象向下转型后,为什么它也能调用派生类新增的函数PrintVersion()呢? 这个暂时不清除为什么,以后知道了再补上,按我的目前的理解,基类对象向下转型后,拿到了派生类所有函数的访问权。 若是哪位大佬路过,还请告知,谢谢。#include <iostream>#include <stri...原创 2020-07-30 15:35:33 · 1257 阅读 · 0 评论 -
C++ this指针了解
1、调用构造函数时,派生类与基类的this都指向下面的p1,另外注意单例函数调用addUser(this),实参this与函数体内的this不同;Person* p1 = new Man("aaa",10,1);// Example program#include <iostream>#include <string>using namespace std;class Person;class Singleton{public: static ..原创 2020-05-19 13:49:53 · 171 阅读 · 0 评论 -
二维数组遍历和排序
要求:有20个长跑队,每队5个人,依次输入各队每个人的身高,然后输出每个队的最高身高1、C语言实现/*20190930*/#include <stdio.h>#define M 20#define N 5int main(){ float run[M][N]; float height_max[M]; int i, j; for(i = 0; i...原创 2019-10-24 10:14:39 · 784 阅读 · 0 评论 -
删除字符串中指定的字符,并返回删除的字符个数
1、用C++实现删除字符串中指定的字符,2、函数int deleteChar(char *s, char c); 其中:*s为字符串指针, c为要删除的字符, 返回值为删除的字符个数;3、函数deleteChar做空指针检测if(NULL == s)//201901009#includ...转载 2019-10-10 13:08:49 · 1360 阅读 · 0 评论