随笔分类 -  深入C++

1 2 下一页
关于指针的传值与传址
摘要:void change(int *p) { *p = 100; } void change2(int **p) { *p = new int(200); } void change3(int *&p) { p = new int(300); } int main() { int a = 1; int *b = new int(2); change(&a); // a = 100 c... 阅读全文
posted @ 2015-03-25 10:54 qinfengxiaoyue 阅读(475) 评论(0) 推荐(0) 编辑
C++:不同类型的指针的本质与差异
摘要:转自:http://blog.csdn.net/richerg85/article/details/10076365 指针的类型(The Type of a Pointer) 一个指向ZooAnimal(一个类)的指针是如何与一个指向整型的指针或者指向template Array的指针有所不同? ZoolAnimal *px; int *pi; Arra... 阅读全文
posted @ 2014-12-17 11:19 qinfengxiaoyue 阅读(2448) 评论(0) 推荐(1) 编辑
C++异常安全
摘要:转自:http://www.cnblogs.com/zgfLawliet/p/3417308.html 异常安全的代码是指,满足两个条件 1异常中立性 : 是指当你的代码(包括你调用的代码)引发异常时,这个异常 能保持原样传递到外层调用代码 2.异常安全性: 抛出异常后,资源不泄露, 抛出异常后,不会使原有数据恶化(例如正常指针变野指针) 少些try catch... 阅读全文
posted @ 2014-05-07 14:39 qinfengxiaoyue 阅读(3066) 评论(0) 推荐(0) 编辑
使用C++11实现完美资源管理
摘要:1.资源管理包括内存管理、文件句柄等等需要进行打开(申请)、关闭(释放)操作的过程 2.VS2010使用的C++规范,严格说来不是C++11,而是C++0x,但是一脉相承的 一:管理数组 相较于auto_ptr,unique_ptr的增强点之一是支持对数组对象指针的管理,比如: struct A { int m_data; A(int n=0){... 阅读全文
posted @ 2014-04-16 21:23 qinfengxiaoyue 阅读(1204) 评论(0) 推荐(0) 编辑
Windows C/C++ 内存泄露检测
摘要:#pragma once #define _CRTDBG_MAP_ALLOC #include #include #include #include #include #include #include #include #ifdef _DEBUG #ifndef DBG_NEW #define DBG_NEW new(_NORMA... 阅读全文
posted @ 2013-12-16 11:14 qinfengxiaoyue 阅读(248) 评论(0) 推荐(0) 编辑
重载类型转换操作符(overload conversion operator)
摘要:详见:http://blog.csdn.net/yby4769250/article/details/7332449 阅读全文
posted @ 2013-11-29 20:18 qinfengxiaoyue 阅读(349) 评论(0) 推荐(0) 编辑
C++程序员必知必会的技巧:RAII
摘要:http://qtandopencv.blogspot.com/2013/10/why-raii-is-must-know-technique-for-c.html 阅读全文
posted @ 2013-11-22 13:09 qinfengxiaoyue 阅读(283) 评论(0) 推荐(0) 编辑
使用auto_ptr需要注意的事项
摘要:注:C++11 已不推荐使用,应使用scoped_ptr/shared_ptr. 部分原因就是如下的注意事项。 转自:http://patmusing.blog.163.com/blog/static/13583496020101824541270/ a. auto_ptr定义于头文件memory中; b. auto_ptr只能用来管理单个动态创建的对象,而不能管理动态创建的数组; ... 阅读全文
posted @ 2013-11-11 13:29 qinfengxiaoyue 阅读(786) 评论(0) 推荐(0) 编辑
C/C++:函数的调用约定(Calling Convention)和名称修饰(Decorated Name)以及两者不匹配引起的问题
摘要:转自:http://blog.csdn.net/zskof/article/details/3475182 注:C++有着与C不同的名称修饰,主要是为了解决重载(overload);调用约定则影响函数参数的入栈顺序和清栈主体;而名称修饰也因调用约定而不同。 调用函数的主体和被调用函数的主体,可能会有不同的调用约定和名称修饰,两者的不匹配会引发问题。 使用C/C++语言开发软件的程序员... 阅读全文
posted @ 2013-10-30 20:09 qinfengxiaoyue 阅读(984) 评论(0) 推荐(0) 编辑
vector/list/set/map 遍历耗时统计
摘要:#include#include #include#include#include#include#include #include using namespace std;#define NUM1 10 //外层循环10次#define NUM2 100000000 //对于int、dword的1亿次i++和++i#define NUM3 100000//对与包含10万个元素容器的iter++... 阅读全文
posted @ 2013-10-29 19:53 qinfengxiaoyue 阅读(1347) 评论(0) 推荐(0) 编辑
关于线程函数结束前显式调用_endthreadex
摘要:1. 本来,MSDN已经明确指出了: You can call _endthread or _endthreadex explicitly to terminate a thread; however, _endthread or _endthreadex is called automatically when the thread returns from the routine pas... 阅读全文
posted @ 2013-05-18 01:09 qinfengxiaoyue 阅读(2208) 评论(0) 推荐(0) 编辑
C++:Stack Unwinding(栈辗转开解)
摘要:节选:http://stackoverflow.com/questions/2331316/what-is-stack-unwinding 1. Stack unwinding is usually talked about in connection with exception handling. Here's an example: void func( int x ){ char... 阅读全文
posted @ 2013-05-18 00:35 qinfengxiaoyue 阅读(837) 评论(0) 推荐(0) 编辑
C++异常处理
摘要:关键字:C++资源管理异常处理 RAII Stack-Unwinding(栈辗转开解)http://blog.csdn.net/daheiantian/article/details/6530318 阅读全文
posted @ 2013-05-18 00:07 qinfengxiaoyue 阅读(159) 评论(0) 推荐(0) 编辑
C++ 模板:奇特递归模板模式(Curiously Recurring Template Pattern -CRTP)和 静多态(Static polymorphism)
摘要:C++: Prefer Curiously Recurring Template Pattern (CRTP) to Template Pattern:http://www.codeproject.com/Tips/537606/Cplusplus-Prefer-Curiously-Recurring-Template-Patt静多态(Static polymorphism):http://en.wikipedia.org/wiki/Template_metaprogramming#Static_polymorphism在“GoF”的设计模式一书中定义的“模板模式”,与C++模板无关,它是一种 阅读全文
posted @ 2013-05-12 19:22 qinfengxiaoyue 阅读(654) 评论(0) 推荐(0) 编辑
从_tiddata看CRT的线程不安全函数
摘要://_tiddata的定义. CRT SRC\mtdll.hstruct _tiddata { unsigned long _tid; /* thread ID */ unsigned long _thandle; /* thread handle */ int _terrno; /* errno va... 阅读全文
posted @ 2013-05-05 22:41 qinfengxiaoyue 阅读(1123) 评论(0) 推荐(0) 编辑
CRT Debugging Techniques / Finding Memory Leaks Using the CRT Library
摘要:关键字:C/C++ CRTDebugging 内存泄露 检测CRT Debugging Techniques :http://msdn.microsoft.com/en-us/library/zh712wwf.aspxFinding Memory Leaks Using the CRT Library : http://msdn.microsoft.com/en-us/library/x98tx3cf.aspx 阅读全文
posted @ 2013-04-24 11:58 qinfengxiaoyue 阅读(156) 评论(0) 推荐(0) 编辑
_beginthread和CreateThread
摘要:转自:http://www.cnblogs.com/project/archive/2011/08/21/2147634.html 为什么要用C运行时库的_beginthreadex代替操作系统的CreateThread来创建线程? 来源自自1999年7月MSJ杂志的《Win32 Q&A》栏目 你也许会说我一直用CreateThread来创建线程,一直都工作得好好的,为什么要用_b... 阅读全文
posted @ 2013-04-20 21:29 qinfengxiaoyue 阅读(559) 评论(0) 推荐(0) 编辑
Windows线程:CreateThread与_beginthreadex解析
摘要:http://www.cnblogs.com/t427/archive/2012/11/17/2775372.html 阅读全文
posted @ 2013-04-20 20:29 qinfengxiaoyue 阅读(201) 评论(0) 推荐(0) 编辑
static_cast, dynamic_cast, reinterpret_cast, const_cast区别比较
摘要:http://www.cnblogs.com/jerry19880126/archive/2012/08/14/2638192.html 阅读全文
posted @ 2013-04-19 02:16 qinfengxiaoyue 阅读(187) 评论(0) 推荐(0) 编辑
关于inline/static inline/extern inline
摘要:http://www.cnblogs.com/openix/archive/2012/11/18/2775625.html 阅读全文
posted @ 2013-04-15 00:03 qinfengxiaoyue 阅读(204) 评论(0) 推荐(0) 编辑

1 2 下一页