文章分类 - 03C&C++
摘要:#include <iostream> /* 适配器模式:让不兼容的接口可以在一起工作 电脑=>投影到=>投影仪上 VGA HDMI TypeC VGA接口的电脑,投影仪也是VAG接口 */ class VGA//VGA接口类 { public : virtual void play() = 0;
阅读全文
摘要:#include <iostream> #include <unordered_map> #include <list> /* 行为模式:主要是关注的对象之间的通信 观察者-监听模式(发布-订阅模式)设计模式:主要关注的是对象的一对多的关系,也就是多个对象都依赖一个对象, 当该对象的状态发生改变时,
阅读全文
摘要:在C++中,函数指针和指针函数是两个相关但不同的概念,让我为您详细解释: 1. 指针函数(函数返回指针) 指针函数是指返回值是指针的函数。 基本语法: type* function_name(parameters); 示例: #include <iostream> using namespace s
阅读全文
摘要:参考 1.从C++到C++/CLI 2.C#调用C++ (使用C++/CLI)
阅读全文
摘要:#include <iostream> #include <typeinfo> #include <string> #include <functional> /* C++ 11 bind绑定器=》返回的结果还是一个函数对象 */ void hello(std::string str) { std:
阅读全文
摘要:举例实现特定function功能 #include<iostream> /* function函数对象类型的实现原理 */ void hello(std::string str) { std::cout << str << std::endl; } int sum(int a, int b) { r
阅读全文
摘要:模板简单基础知识 #include<iostream> template<typename T> bool compare(T a, T b) { std::cout << "bool compare(T a, T b)" << std::endl; return a > b; } template
阅读全文
摘要:function简单使用 #include <iostream> #include <vector> #include <functional>//使用function函数对象类型 #include <algorithm> /* C+11 提供的绑定器和函数对象 bind function C++
阅读全文
摘要:#include <iostream> #include <vector> #include <functional> #include <algorithm> /* 绑定器和函数对象operator() 1.C++ STL中绑定器 bind1st:operator()的第一个形参变量绑定成一个确定
阅读全文
摘要:#include <iostream> #include <vector> #include <functional> #include <algorithm> /* 绑定器和函数对象operator() 1.C++ STL中绑定器 bind1st:operator()的第一个形参变量绑定成一个确定
阅读全文
摘要:问题的引出 #include <iostream> #include <memory> #include <thread> using namespace std; /* 多线程访问共享对象的线程安全问题 */ class A { public: A() { cout << "A()" << end
阅读全文
摘要:#include <iostream> #include <memory> #include <functional> //#include <cstdio> /* 智能指针的删除器 delete 智能指针:能够保证资源绝对的释放 delete ptr 但向开辟的的数组空间,打开文件资源不能用智能指
阅读全文
摘要:在 C++ 中实现线程的安全退出,核心是让线程能够“优雅地”结束执行,避免强制终止(如 pthread_cancel 或 terminate)导致的资源泄漏或数据不一致。以下是几种常用的线程安全退出方案: 1. 标志位退出法(最常用) 通过一个共享的原子变量(或加锁保护的变量)作为“退出标志”,线程
阅读全文
摘要:好的,这是一个非常基础且重要的问题!C++中指针大小是4字节或8位的原因直接关联到计算机系统的核心架构。 🖥️ 根本原因:CPU的寻址能力 指针大小由CPU的地址总线宽度决定,因为它存储的是内存地址。 32位系统(4字节指针) 地址总线:32位 可寻址空间:2³² = 4,294,967,296
阅读全文
摘要:以下是使用C++编写的计算三角形面积的函数,使用三个点的坐标作为参数: 向量叉积公式 #include <cmath> double calculateTriangleArea(double x1, double y1, double x2, double y2, double x3, double
阅读全文
浙公网安备 33010602011771号