随笔分类 - C++开发
1
摘要:问题:在项目开发中,试图把类的非static成员函数的指针赋值给普通函数指针变量(前提当然是函数定义是一样的),结果编译不过。原因:类的非static成员函数包含一个隐含的this指针。在某些calling convention下,this指针作为函数的附加参数入栈,相当于多了一个参数传入。另一个更通用的解释是:非static的成员函数指针的定义和调用都需要指明作用到哪个类/具体对象上,明显与一般函数指针的定义和调用是不兼容的。我的理解是非static的成员函数指针只是一个offset,因此需要在获取对象指针的基础上进行函数调用才行。类的静态成员函数采用与一般函数指针相同的调用方式,而受thi
阅读全文
摘要:Two ways to make use of it:1) directly declare a function pointer variable at the place where it's required. like below:void (*pFunc)(int); // pFunc is a variable herepFunc = &FuncA;pFunc(2);2) typedef a function poiner type and then use it. like below:typedef void (*pFunc)(int);pFunc pFuncO
阅读全文
摘要:来自:c++ containers cheat sheet
阅读全文
摘要:Function object, also called functor, functional, or functionoid,is a computer programming construct allowing an object to be invoked or called as though it were an ordinary function, usually with the same syntax.Several notes for it:1. In C, there is only function pointer; in C#, there is only dele
阅读全文
摘要:CRT provides a set of debug routines for helping debugging issues. About assertion, it provides two:1. _ASSERT. This macro will only evaluate the expression and pop up diagnostic dialog if assert fail...
阅读全文
摘要:转载整理自:关于虚函数那点破事问题:如果你是C++程序员,我想你可能遇到过这样的情况: 在debug时,对着一个函数step into,明明调用的是A函数,可是结果却跳进了B函数。 为什么,call stack里显示的也是明明白白,就是直接进了B函数。百思不得其解,于是你怀疑是不是系统出了问题,是不是编译器出了问题,是不是调试器出了问题~~~ 其实那些玩意不是那么容易出错的,先看看你你的A,B函数...
阅读全文
摘要:摘自: 如何快速定位一个函数的返回点如何快速定位一个函数的返回点,这对于一个比较短小精悍的函数来讲,从来就不是问题,但是假设我们有一个名为LongFunction的1000行长的函数, 调用如下: 1bool bSuccess = LongFunction();2assert(bSuccess); 在运行中第二行弹出一个assert,我们知道肯定是LongFunction内部运行中出了什么问题导...
阅读全文
摘要:这个一个google主持的开源项目,http://code.google.com/p/googletest/ gtest在google的很多其他的开源项目中都使用到了,如:chromium gtest的优点,就是写案例简单,并且跨平台,有一定的可扩展性 用TEST这个宏加上我们的代码就可以生产一个案例,例如: TEST(FactorialTest, Zero) { EXPECT_EQ(1, Fac...
阅读全文
摘要:Whole topic can be found:C++ Exception Handling1. C++ Exception Specification(http://msdn.microsoft.com/en-us/library/wfa0edys%28VS.80%29.aspx)Visual C++ departs from the ANSI Standard in its implemen...
阅读全文
摘要:As we all know, dll's entry point is DllMain(). Now consider when to initialize all global and static data, the time happens earlier than calling DllMain()!You can easily know this by debugging.In CRT...
阅读全文
摘要:一般在C或C++中(VC当然是C++的一种),DLL的模块入口点有个默认函数,是_DllMainCRTStartup(),它的原形与 DllMain()一样,链接器在链接的时候就是以它作为模块的入口函数,那样它就可以进行一些模块全局变量等的初始化操作,当然用户也可对模块入口地址 进行自行设定,不过不建议这么做!当链接器在链接时,它会自动查找当前DLL模块工程中的各个.obj文件,如果找到有DllM...
阅读全文
摘要:三个WINDOWS SDK函数: WinExec,ShellExecute ,CreateProcess,可以实现调用其他程序的要求。WinExec这个函数最简单,只有两个参数,原型如下: UINT WinExec( LPCSTR lpCmdLine, // 命令路径 UINT uCmdShow // 显示方式 ;使用方法如下:WinExec("Notepad.exe", SW_SHOW); //...
阅读全文
摘要:Static/globa dataLifecycle:All static data and global data would be stored in static/global storage area for the whole application. Dll's static and global data would be there of course. In general, t...
阅读全文
摘要:[转载自:http://www.vckbase.com/document/viewdoc/?id=1720] C++的static有两种用法:面向过程程序设计中的static和面向对象程序设计中的static。前者应用于普通变量和函数,不涉及类;后者主要说明static在类中的作用。 一、面向过程设计中的static 1、静态全局变量 在全局变量前,加上关键字static,该变量就被定...
阅读全文
摘要:Since Struct and Class are almost the same thing, I will just talk about one of the two. Let's talk about struct ba. There are three kinds struct: 1. Only contain data member without functions. 2. hav...
阅读全文
摘要:Whitespace : In computer science, whitespace is any single character or series of characters that represents horizontal or vertical space in typography. When rendered, a whitespace character does not ...
阅读全文
摘要:In c++, we should keep using c style union. Although c++ union supports constructor, we'd better not use it. Actually, no need to use constructor for union basically. Going deeper, even as the expande...
阅读全文
摘要:Preprocessor directives can appear anywhere in a source file, but they apply only to the remainder of the source file. #error:Error directives produce compiler-time error messages. #if !defined(__cpl...
阅读全文
摘要:Exporting from a DLL A DLL file has a layout very similar to an .exe file, with one important difference — a DLL file contains an exports table. The exports table contains the name of every function...
阅读全文
摘要:LoadLibrary HMODULE WINAPI LoadLibrary( __in LPCTSTR lpFileName ); Return Value If the function succeeds, the return value is a handle to the module.If the function fails, the return value is NULL. To...
阅读全文
1

浙公网安备 33010602011771号