为什么需要allocator的rebind接口
摘要:from:http://topic.csdn.net/u/20080226/04/d3187cbf-c72e-4f29-b6f0-ed05e1f65f95.html laomai rebind的本质应该这么说:给定了类型T的分配器Allocator=allocator<T>,现在想根据相同的策略得到另外一个类型U的分配器allocator<U>,那么allocator<U> = allocator<T>::Rebind<U>::other.之所以要提供rebind界面,是因为容器只知道模板参数名Allocator,而不是其具体实现,容
阅读全文
C++中extern “C”含义深层探索(zz)
摘要:1.引言 C++语言的创建初衷是“a better C”,但是这并不意味着C++中类似C语言的全局变量和函数所采用的编译和连接方式与C语言完全相同。作为一种欲与C兼容的语言,C++保留了一部分过程式语言的特点(被世人称为“不彻底地面向对象”),因而它可以定义不属于任何类的全局变量和函数。但是,C++毕竟是一种面向对象的程序设计语言,为了支持函数的重载,C++对全局函数的处理方式与C有明显的不同。2.从标准头文件说起 某企业曾经给出如下的一道面试题: 面试题 为什么标准头文件都有类似以下的结构?1#ifndef__INCvxWorksh2#define__INCvxWorksh3#ifd...
阅读全文
编译C++出现错误:Cannot open precompiled header file
摘要:在编译vc时出现了这样的错误,因为这个程序不是本人写的,可能是编写环境的设置问题。所以在自己的电脑上会出现这样的错, (我用的是中文版的vc 6.0) fatal error C1083: Cannot open precompiled header file: \'Debug/v13_3.pch\': No such file or directory 在网上搜集了一下,这个错误是预编译文件的设置造成的,有几种可以尝试的途径: 1)单独编译StdAfx.cpp 2)编译所有 (即按Ctrl+F7) 3)在工程-设置-c++-最下面的工程选项里去掉××。Pc
阅读全文
How to avoid error "LNK2001 unresolved external" by using DEFINE_GUID
摘要:原文:http://support.microsoft.com/kb/130869In Microsoft Visual C++, if the version of the compiler is older than a specific version, a GUID must be initialized exactly once. For this reason, there are two different versions of the DEFINE_GUID macro. One version just declares an external reference to t
阅读全文
Reference vs. Pointer
摘要:from: http://edu.codepub.com/2010/0607/23314.php 了解引用reference与指针pointer到底有什么不同可以帮助你决定什么时候该用reference,什么时候该用 pointer。 在C++ 中,reference在很多方面与指针(pointer)具有同样的能力。虽然多数C++程序员对于何时使用reference何时使用pointer 都会有一些直觉,但总还是会有些时候搞不清楚。如果你想要建立一个关于使用reference使用的清晰有理的概念,又有必要了解到底reference 和pointer有什么不同。 深层含义 与pointer 类.
阅读全文
STL Allocator
摘要:rebind from: http://topic.csdn.net/u/20080226/04/d3187cbf-c72e-4f29-b6f0-ed05e1f65f95.html rebind的本质应该这么说:给定了类型T的分配器Allocator=allocator<T>,现在想根据相同的策略得到另外一个类型U的分配器allocator<U>,那么allocator<U> = allocator<T>::Rebind<U>::other.之所以要提供rebind界面,是因为容器只知道模板参数名Allocator,而不是其具体实现,
阅读全文
How slow is dynamic_cast?
摘要:C++ users are advised frequently not to use dynamic_cast, because it's slow. I thought it would be nice to measure this, so I made up a test on Visual C++. All you need is a simple hierarchy of types with a baseclass, a derived class, and another class derived from that. The test is this: if you
阅读全文
Type Casting in C++
摘要:Converting an expression of a given type into another type is known as type-casting. We have already seen some ways to type cast: Implicit conversionImplicit conversions do not require any operator. They are automatically performed when a value is copied to a compatible type. For example: Here, th..
阅读全文
How to interpret complex C/C++ declarations (ZT)
摘要:from: http://www.codeproject.com/KB/cpp/complex_declarations.aspxContentsIntroductionThe basicsThe const modifierThe subtleties of typedefFunction pointersThe right-left rule [Important]Further examplesSuggested readingCredits IntroductionEver came across a declaration like int * (* (*fp1) (int) ) [
阅读全文
sizeof 总结和类成员布局
摘要:根据C++ Complete Reference 对如下链接进行勘误http://blog.csdn.net/chief1985/archive/2009/10/23/4720191.aspxhttp://blog.csdn.net/wuliming_sc/archive/2009/01/31/3855607.aspx
阅读全文
C++ 虚函数表
摘要:C++中的虚函数的作用主要是实现了多态的机制。关于多态,简而言之就是用父类型别的指针指向其子类的实例,然后通过父类的指针调用实际子类的成员函数。这种技术可以让父类的指针有“多种形态”,这是一种泛型技术。所谓泛型技术,说白了就是试图使用不变的代码来实现可变的算法。比如:模板技术,RTTI技术,虚函数技术,要么是试图做到在编译时决议,要么试图做到运行时决议。虚函数表对C++ 了解的人都应该知道虚函数(Virtual Function)是通过一张虚函数表(Virtual Table)来实现的。简称为V-Table。 在这个表中,主是要一个类的虚函数的地址表,这张表解决了继承、覆盖的问题,保证其容真实
阅读全文
C++ FAQ for me
摘要:1. 为什么需要虚析构函数,什么时候需要?看下面的代码:虚析构函数 Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->classClxBase{public:ClxBase(){};virtual~ClxBase(){cout<<"OutputfromthedestructorofclassClxBase!"<<endl;};virtualvoidDoSomething(){cout<<&
阅读全文
Static 关键字 C and C++
摘要:C++的static有两种用法:面向过程程序设计中的static和面向对象程序设计中的static。前者应用于普通变量和函数,不涉及类;后者主要说明static在类中的作用。 一、面向过程设计中的static 1、静态全局变量 在全局变量前,加上关键字static,该变量就被定义成为一个静态全局变量。静态全局变量有以下特点: 该变量在全局数据区分配内存; 未经初始化的静态全局变量会被程序自动初始化为0(局部变量的值是随机的,除非它被显式初始化); 静态全局变量在声明它的整个文件都是可见的,而在文件之外是不可见的; 全局和静态全局变量只在程序开始运行时初始化; 未初始化的全局和静态全局变...
阅读全文
C++之虚拟继承
摘要:定义: class B { private: B() { } friend class A; }; 将导致B无法被除A以外的其它任何class直接继承以后实例化,也就是说,在上面这个定义的基础上,如果你再定义: class C:public B{}; 将导致编译能够通过,但是无法实例化C(那当然也没用了,所以间接实现了一个无法继承的类B),但是因为A是B的友元,所以能够进入B的private区域,所以如果定义: class A:public B{}; 能够实例化A. 但是这样定义还有一个漏洞,如果在A普通public继承B的基础上再定义: class D:publ...
阅读全文
MFC基本概念理解
摘要:CFrameWndFrame windows are windows that frame an application or a part of an application. Frame windows usually contain other windows, such as views, tool bars, and status bars. In the case of CMDIFrameWnd, they may contain CMDIChildWnd objects indirectly. CDocumentA document represents the unit of
阅读全文
.def文件与__declspec(dllexport)
摘要:A module-definition (.def) file is a text file containing one or more module statements that describe various attributes of a DLL. If you are not using the __declspec(dllexport) keyword to export the DLL's functions, the DLL requires a .def file.A minimal .def file must contain the following mod
阅读全文
COM技术内幕笔记
摘要:1. _stdcall是指被调用的函数会在返回调用者时自行负责将参数等从栈中移除。所有的Win32 API都是使用这个调用约定的,带有变参的函数还是使用_cdecl。Windows使用_stdcall是因为这种约定可以减少代码大小,而且早期Windows是运行在640KB内存的机器上的。2. CoCreateInstance:使用指定的clsid创建一个未初始化的COM对象。Call CoCreateInstance when you want to create only one object on the local system. To create a single object on
阅读全文
COM thread model
摘要:In general, the simplest way to view the COM threading architecture is to think of all the COM objects in the process as divided into groups called apartments. A COM object lives in exactly one apartment, in the sense that its methods can legally be directly called only by a thread that belongs to t
阅读全文
Precompiled header
摘要:In computer programming, a pre-compiled header is a technique used by some C or C++ compilers to reduce compilation time.In the C and C++ programming languages, a header file is a file whose text may be automatically included in another source file by the compiler, usually specified by the use of co
阅读全文
const 与指针(zz)
摘要:1. 指向const对象的指针到目前位置,我们使用指针来修改其所指对象的值.但是如果指针指向const对象,则不允许用指针来改变其所指的const值.为了保证这个特性,C++语言强制要求指向const对象的指针也必须具有const特性:const double *cptr; //cptr may point to a double that is const这里的cptr是一个指向double类型的const对象的指针,const限定了cptr指针所指向的对象类型,而并非cptr本身,也就是说,cptr本身并不是const.在定义时不需要对它进行初始化,如果需要的话,允许给cptr重新赋值,使
阅读全文