![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c++
文章平均质量分 67
a1317338022
这个作者很懒,什么都没留下…
展开
-
多线程
线程同步可以通过unique_lock来控制,效果因该比使用mutex的lock和unlock好一些,unique_lock和lock_guard会自动释放锁资源,线程同步加锁统一比较简单,没有额外的代码,重要的是控制锁的大小,如果过大可能会影响程序的执行效率,容易出现问题,所以锁的大小适当就好,可以通过加一个大括号来控制锁的什么周期,以便及时释放锁资源,只需要在适当的时候加上锁就好了,代码如下: { std::unique_lock<st...原创 2021-04-06 10:48:10 · 215 阅读 · 0 评论 -
收藏的一些有用的c++宏定义
#define QT_SAFE_DELETE(p) do { if(p) { delete (p); (p) = 0; } } while(0)#define QT_SAFE_DELETE_ARRAY(p) do { if(p) { delete[] (p); (p) = 0; } } while(0)#define QT_BREAK_IF(cond) ...原创 2019-12-03 21:55:04 · 204 阅读 · 0 评论 -
访问者模式 c++ boost
以下是我理解的观察者模式:#include "stdafx.h"#include using namespace std;//被访问对象//抽象访问者class ByVisitor;class Visitor;// "Element" class Element { public: // Methods virtual原创 2016-11-13 18:15:46 · 749 阅读 · 0 评论 -
适配器模式
#include "stdafx.h"#include #include #include #include using namespace boost;//客户端类class Target{public: Target(){} virtual ~Target(){} //该接口用于适配其他类的接口函数 virtual void requireFunc() {原创 2016-11-15 00:02:43 · 341 阅读 · 0 评论 -
装饰模式
#include "stdafx.h"#include using namespace std;//组件抽象类class Component{public:virtual void operate(){}virtual ~Component(){}protected://构造函数声明为保护的成员,外部不能创建,表明只能在内部创建Compo原创 2016-11-15 00:17:59 · 335 阅读 · 0 评论 -
Template 模块模式
模块模式(Template)其实就是使用虚函数实现多态性,不同类的实例调用同一个接口,得到不同的结果:#include "stdafx.h"#include using namespace std;class ObstractClass{public: ObstractClass(){} virtual void func1() { cout << "func1" <<原创 2016-11-16 22:39:10 · 739 阅读 · 0 评论 -
代理模式
#include "stdafx.h"#include #include #include using namespace boost;//主角1抽象类class Subject{public: Subject(){} virtual ~Subject(){} //需要代理的2个功能函数 virtual void requestFunc1(){} virtual vo原创 2016-11-15 22:22:38 · 347 阅读 · 0 评论 -
C++11心得笔记
大致看完了>这本书籍,终结一下心得:总的来说c++11有很多优秀的特性是和boost,python,java类似的,就不如boost里面的智能指针,lambda匿名函数等已经加入到c++11的标准了,还有python的元组,原生字符串R等也引入到了c++11的标准了,下面详细列一下c++11中我觉得对自己挺有用的特性:1.c++11中加入了__func__的功能,表示在哪个函数,在pyth原创 2017-03-07 06:48:50 · 385 阅读 · 0 评论 -
C++ 虚函数表解析
C++ 虚函数表解析 陈皓http://blog.csdn.net/haoel 前言 C++中的虚函数的作用主要是实现了多态的机制。关于多态,简而言之就是用父类型别的指针指向其子类的实例,然后通过父类的指针调用实际子类的成员函数。这种技术可以让父类的指针有“多种形态”,这是一种泛型技术。所谓泛型技术,说白了就是试图使用不变的代码来实现可变的算法。比如:模板技术,R转载 2017-03-09 01:42:33 · 307 阅读 · 0 评论 -
C++效率编程心得
try{ destroyRes(); throw();}catch(...)//捕捉所有的异常{}//不加任何代码,否则catch中也有可能抛出异常看完了Effective c++和More Effective c++ 2本书,把自己的一些心得写下来: 1.尽量以const,enum,enum class,enum,inline代替define宏; 2.尽可能的使用con原创 2017-03-08 00:25:58 · 697 阅读 · 0 评论 -
MFC Win32程序打开选择目录对话框并获得绝对路径
TCHAR szFolderPath[MAX_PATH] = { 0 }; BROWSEINFO sInfo; ::ZeroMemory(&sInfo, sizeof(BROWSEINFO)); sInfo.pidlRoot = 0; sInfo.lpszTitle = _T("请选择一个文件夹:"); sInfo.ulFlags =原创 2017-02-15 16:55:38 · 1213 阅读 · 0 评论 -
error C2511: 'xx函数' : overloaded member function not found in xx类
当报error C2511: 'xx函数' : overloaded member function not found in xx类错误时,可能是因为定义的函数不恰当,比如你声明了一个const的成员函数,在cpp里面里面定义该成员函数时没有加上const就会报这个错误,所以在定义const成员函数时,如果是const成员函数,在定义的时,是需要加上const的,否则就会编译原创 2017-02-15 10:17:42 · 7168 阅读 · 0 评论 -
Boost 常用的编译命令
bjam toolset=msvc --with-system stage release threading=multi link=shared link=static runtime-link=shared runtime-link=staticb2 --buildtype=complete link=static runtime-link=static install这是完全编译命令原创 2017-02-23 13:48:18 · 813 阅读 · 0 评论 -
c++ 复制文件
c++复制文件有多种方式,比如可以采用system输入dos命令,他会弹出终端窗口,或者通过copyfile函数进行复制 if (!CopyFile(str + _T("\\data.fba"), __m_strPath + _T("\\data.fba"), FALSE)) { ::MessageBox(NULL, _T("安装过程失败"), NULL, NULL);原创 2017-02-22 16:31:16 · 2460 阅读 · 0 评论 -
Fadeca 外观模式
#include "stdafx.h"#include #include #include using namespace boost;//外观模式就是为需要在多个类实例调用接口函数//通过外观模式打包成一个统一的接口,方便调用class System1{public: System1(){} virtual ~System1(){} void func1(原创 2016-11-15 22:25:58 · 415 阅读 · 0 评论 -
Flyweight 享元模式
#include "stdafx.h"#include #include #include #include #include #include #include #include #include using namespace boost;class FlyWeight{public: FlyWeight(const std::string& strData)原创 2016-11-16 22:29:08 · 368 阅读 · 0 评论 -
版本控制工具 Git SVN使用总结
在Windows上搭建Git ServerGit在版本控制方面,相比与SVN有更多的灵活性,对于开源的项目,我们可以托管到Github上面,非常方便,但是闭源的项目就会收取昂贵的费用。那么私有项目,如何用Git进行代码版本控制呢?我们可以自己构建Git服务器。一般来说,在Linux上搭建Git的教程比较多,但是如何在Windows Server平台下搭建Git服务器呢?对于...转载 2019-06-22 21:53:09 · 646 阅读 · 0 评论 -
分布式编译工具increbuild
Mark一下!前几天,给公司cpp开发人员弄了个和vs兼容的分布式编译工具increbuild。官网下载地址http://www.xoreax.com/incredibuild-download-center.htm,另附上一个破解版下载地址:http://ishare.iask.sina.com.cn/f/15255067.html?from=dl(360报毒)。工具本身安装和使用非常...转载 2018-09-19 21:41:40 · 1477 阅读 · 0 评论 -
Qt MVC入门2 - 模型索引
Model indexesTo ensure that the representation of the data is kept separate from the way it is accessed, the concept of a model index is introduced. Each piece of information that can be obtained vi...原创 2018-08-15 18:15:39 · 396 阅读 · 0 评论 -
MFC 外部普通函数获取类对象指针来调用类的成员函数
//外部普通函数获取内部类对象指针,这种方法不行,可以通过this全局变量来达到这个目的 //CActiveXVidyoCtrl *pDlg123 = (CActiveXVidyoCtrl*)(AfxGetApp()->GetMainWnd());XXDlg *g_pDlg = NULL;//全局变量xxx::XXX()//构造函数{g_pDlg = this;}原创 2017-12-25 18:00:55 · 1532 阅读 · 0 评论 -
网页加载ActiveX控件
我在做网页加载在ActiveX控件需要按一下步骤进行:1.管理员权限打开终端:输入 regsvr32 xxx.ocx2.regedit打开注册表,搜索xxx.ocx对应的uuid3.编写测试html 简单的OCX控件调用 function login() { alert("aaaaaaaaaaaaaaaaaaa"); var palyob原创 2017-12-25 11:03:03 · 3428 阅读 · 0 评论 -
error LNK2001: 无法解析的外部符号 _main
但在编译debug版本控制台应用程序的时候,可以正常编译运行,当切换到release版本的时候编译报了以下错误:1>MSVCRT.lib(crtexe.obj) : error LNK2001: 无法解析的外部符号 _main1>C:\Users\JiangYang\Desktop\simplest_ffmpeg_device\Release\simplest_ffmpeg_readcam原创 2017-10-18 14:43:07 · 10626 阅读 · 0 评论 -
必须要用初始化列表的几种情况
1. 类成员为const类型2. 类成员为引用类型#include using namespace std;class A{ public: A(int &v) : i(v), p(v), j(v) {} void print_val() { cout "hello:" " " endl;} private:转载 2016-12-03 21:37:09 · 4400 阅读 · 0 评论 -
C++使用初始化列表提高效率
C++使用初始化列表提高效率(转):转自:http://www.cnblogs.com/graphics/archive/2010/07/04/1770900.html何谓初始化列表与其他函数不同,构造函数除了有名字,参数列表和函数体之外,还可以有初始化列表,初始化列表以冒号开头,后跟一系列以逗号分隔的初始化字段。在C++中,struct和class的唯一区别是默认的访转载 2017-07-16 13:40:53 · 511 阅读 · 0 评论 -
工厂模式 Factory
#include "stdafx.h"#include #include #include #include using namespace boost;enum Product_No{PRODUCT_1, PRODUCT_2}g_enumProductNo; class Product{protected: Product(){} Product(const std:原创 2016-11-17 22:13:43 · 385 阅读 · 0 评论 -
Composite 组合模式
组合模式就是整体与部分的关系,当部分中需要动态的添加或移除时,可以考虑用组合模式,其中的关系类似与数据库中表与记录的关系:#include "stdafx.h"#include #include #include using namespace std;class Component{public: Component(){} virtual ~Component(){}原创 2016-11-16 22:40:47 · 437 阅读 · 0 评论 -
Memento 备忘录模式
#include "stdafx.h"#include #include using namespace std;class Originator;class Memento{private: friend class Originator;//类Originalor内部可以访问Memento的私有成员 string __m_strData; Memento() { }原创 2016-11-16 22:34:08 · 328 阅读 · 0 评论 -
Duilib程序中弹出文件对话框
在Duilib程序中或者Window32程序中,加载文件对话框可以通过以下代码进行加载,头文件可以百度:void CDuiFrameWnd::OpenFileDialog(){ OPENFILENAME ofn; TCHAR szFile[MAX_PATH] = _T(""); ZeroMemory(&ofn, sizeof(ofn)); o原创 2017-02-14 17:00:17 · 3615 阅读 · 0 评论 -
Duilib程序中出现pRoot为NULL,调用xml失败
在Duilib的项目中,有以下的代码:出现了以下错误:可以调试代码发现是因为xml文件没有加载成功,可以打断点发现str的值加上"skin"所在的目录没有xml文件,xml文件具体在哪个文件夹可以根据具体情况进行调整,当把代码调整为如下代码是,可以正常运行:原创 2017-02-14 16:35:35 · 1565 阅读 · 0 评论 -
职责链模式
避免请求发送者与接收者耦合在一起,让多个对象都有可能接收请求,将这些对象连接成一条链,并且沿着这条链传递请求,直到有对象处理它为止,这就是职责链模式。#include "stdafx.h"#include #include #include #include using namespace boost;//职责链模式就是一个请求提交给//职责链中一连串的对象,如果遇到了//符原创 2016-11-20 17:24:53 · 290 阅读 · 0 评论 -
Command 命令模式
在开发过程中,我可能会需要向某些对象发送一些请求,但是我们不知请求的具体接收者是谁,也不知道被请求的操作是那个,我们只知道在程序运行中指定具体的请求接收者即可。打个比方,电视遥控器,我们只需要知道按那个按钮能够打开电视、关闭电视和换台即可,并不需要知道是怎么开电视、关电视和换台的。对于这种情况,我们可以采用命令模式来进行设计。 一、基本定义原创 2016-11-20 15:56:57 · 603 阅读 · 0 评论 -
Mediator 中介者模式
Mediator.h文件:#include "stdafx.h"#include #include #include #include #include #include using namespace boost;typedef std::string ColleageAData;typedef long ColleageBData;class Mediator;原创 2016-11-20 11:30:03 · 463 阅读 · 0 评论 -
State 状态模式 状态机
#include "stdafx.h"#include #include #include #include #include #include using namespace boost;class Context;class State{public: virtual void Operation(shared_ptr) = 0; virtual void Ch原创 2016-11-20 10:06:13 · 446 阅读 · 0 评论 -
策略模式 Strategy
#include "stdafx.h"#include #include #include #include #include using namespace boost;class Strategy{public: virtual void AlgorithmStragegy() = 0;};class StrategyA : public Strategy原创 2016-11-19 23:16:49 · 316 阅读 · 0 评论 -
Bridge 桥接模式
#include "stdafx.h"#include #include #include #include #include using namespace boost;#define CC_SYNTHESIZE(varType, varName, funName)\protected: varType varName;\public: virtual varType get原创 2016-11-19 22:47:58 · 306 阅读 · 0 评论 -
Prototype
#include "stdafx.h"#include #include #include #include using namespace boost;#define CC_SYNTHESIZE(varType, varName, funName)\protected: varType varName;\public: virtual varType get##funName原创 2016-11-19 19:23:59 · 323 阅读 · 0 评论 -
Builder 创建者模式 构造者模式
#include "stdafx.h"#include #include #include #include using namespace boost;#define CC_SYNTHESIZE_PRIVATE(varType, varName, funName)\private: varType varName;\public: virtual varType get##f原创 2016-11-19 18:44:23 · 371 阅读 · 0 评论 -
Observer 观察者模式
#include "stdafx.h"#include #include #include #include #include #include #include using namespace boost;//使用类的继承,抽象类可以实现多态和提高内聚性//主角1数据typedef struct _Subject1Data{ int iId; std::stri原创 2016-11-19 12:03:36 · 296 阅读 · 0 评论 -
Singleton 单例模式
#include "stdafx.h"#include #include #include #include #include using namespace boost;// class SingletonObject// {// public:// static shared_ptr getInstene()// {// if (NULL == __m_ptrSi原创 2016-11-19 12:02:31 · 265 阅读 · 0 评论 -
访问者模式
#include "stdafx.h" - =\00#include #include using namespace std;class Element;class Elem原创 2016-11-15 00:23:14 · 270 阅读 · 0 评论