- 博客(57)
- 收藏
- 关注
原创 利用lambda find_if实现map通过value 寻找打印所有的key
利用lambda find_if实现map通过value 寻找打印所有的key
2022-08-14 23:11:25
473
原创 观察者模式
观察者模式包含如下角色:Subject: 目标ConcreteSubject: 具体目标Observer: 观察者ConcreteObserver: 具体观察者代码实现 用智能指针作为封装
2022-06-20 00:08:03
121
原创 c++提供的4种类型转换
看代码注释即可#include <iostream>class A{public: virtual void func() { std::cout << "I'm A" << std::endl; }};class B :public A{public: virtual void func() { std::cout << "I'm B" << std::endl; }};/************
2022-05-29 22:39:41
199
原创 lambdas表达式详细使用
结合侯捷老师的视频 和cpprefenrence 所写的测试和用法逐个运行 即可了解其用法#include <iostream>#include <set>using namespace std;void test(){ [] { cout << "hello lambda" << endl; }(); //print hello auto l = [] { cout << "hello lambda" <
2022-05-04 22:56:14
560
原创 智能指针之unique_ptr 详细使用大全
#include <iostream>#include <memory>#include <vector>using namespace std;class Point{public: Point(int x = 0, int y = 0) :m_x(x), m_y(y) { cout << "constructor " << m_x << endl; } Point(const Point& .
2022-05-03 23:43:56
1625
原创 c++无参构造函数(栈和堆的区别)
#include <iostream>using namespace std;class Test{public: Test() { cout << "T constructor" << endl; } ~Test() { cout << "T destructor" << endl; } };Test t2(){ Test *p3 = new Test; cout << "t2 funct.
2022-05-02 20:06:55
996
原创 指针数组和数组指针的说明及使用
#include <iostream>#include <string>using namespace std;void print(int p2[][3]){ for (int i = 0; i < 2; ++i) { for (int j = 0; j < 3; ++j) { cout << p2[i][j] << " "; } cout << endl; }}void print2(int(*p.
2022-05-02 10:39:08
222
原创 c++ 关键字 explicit
C++11之前只可以用与防止单个参数(泛指,因为多个参数在使用默认实参时也可以认为是单个参数) ,使用于构造函数 防止其进行隐式转换class Myclass {public: explicit Myclass(int r, int im = 0) :m_r(r),m_im(im) {} void print() { cout << "m_r = " << m_r << ";m_im = " << m_im << endl;
2022-03-11 20:32:08
763
原创 条件变量之生产者与消费者
head.h#ifndef HEAD_H#define HEAD_H#include <stdio.h>#include <unistd.h>#include <pthread.h>#include <errno.h>#include <string.h>#include <stdlib.h>typedef struct{ int resource; pthread_mutex_t lock;
2022-01-17 23:48:23
285
原创 工厂模式(简单工厂模式,抽象工厂模式)
1.简单工厂模式利用多态来实现简单工厂模式(继承,纯虚函数)下方例子展示不同面积的计算1.1.父类(仅实现头文件即可,用纯虚函数,析构函数设置为虚函数)#ifndef AREA_H#define AREA_H#include <iostream>using namespace std;class Area{public: virtual void showArea() = 0; virtual float calcuArea() = 0; virtual ~
2022-01-16 23:47:34
217
原创 stdarg可变参数
#include <stdarg.h>#include <stdio.h>int sum(int args, ...);int sum(int args, ...) { // 三个圆点为占位符 int i = 0; int sum = 0; va_list vap;//定义参数列表 va_start(vap, args);//初始化参数列表,args为第一个参数的名字 代表了多少个 for (i = 0; i < args; ++i) { sum += .
2022-01-03 11:01:45
547
原创 2.4随机数生成(整数、长整形、浮点数)
1.整数(rand、srand)#include <stdio.h>#include <stdlib.h>int main(){ int i, j, k; srand((int)time(NULL)); for (i = 0; i < 10; ++i) { j = 1 + (int)(10.0*rand() / (RAND_MAX + 1.0));//生成1-10的整数 printf("%d ", j); } printf("\n"); fo
2022-01-02 23:08:07
742
原创 回调函数:函数指针的使用(函数指针不同的定义调用、typedef的使用,万能指针void*的使用)
1.函数指针的两种定义方式及调用#include <stdio.h>int add(int a, int b){ return a + b;}int main(){ int(*p)(int a, int b) = NULL;//定义函数指针 int(*p1)(int, int) = NULL;//形参可以省略,定义函数指针 p = add;//指向 p1 = add; int sum = (*p)(3, 4);//调用 int sum1 = p1(3, 4);//
2022-01-02 22:10:35
871
原创 02回声服务端与客户端(瑕疵版)
产生问题的原因是TCP不存在数据边界(粘包问题)client.c#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <arpa/inet.h>#include <sys/socket.h>#define BUF_SIZE 1024void serErr(const char *message);i
2021-12-26 22:10:52
1361
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人