随笔分类 - C/C++/STL/Boost
摘要:C++0x :: Introduction to some amazing features View more presentations from Christian S. Perone
阅读全文
摘要:restrict是C99引入的关键字,该关键字适用于指针的声明,并表明指针是访问一个数据对象的唯一且初始的方式,由此编译器可以进行一些优化。例1搞自:http://www.blogjava.net/killme2008/archive/2007/08/04/134399.htmlint ar[10];int * restrict restar=(int *)malloc(10*sizeof(int));int *par=ar;这里说明restar是访问由malloc()分配的内存的唯一且初始的方式。par就不是了。那么:for(n=0;n<10;n++){ par[n]+=5; res.
阅读全文
摘要:Table of Contents1 timer 2 progress_timer 3 progress_display 1 timertimer t; //声明一个timer类对象t,调用构造函数开始计时timer t(t0); //调用默认的复制构造函数,t的流逝时间与t0相同成员函数:elapsed() 流逝的时间elapsed_max() 计时器最大范围elapsed_min() 计时器最小范围restart() 重新开始计时2 progress_timer 该类构造函数开始计时,析构函数则在适当的位置以适当的形式打印自构造函数调用开始到析构函数调用的时间。3 progress_dis
阅读全文
摘要:官方文档:http://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.htmlC99标准引入了Designated Initializers特性使得数组、结构体和联合体的初始化更加灵活和方便。对于一个数组:int a[10] = { [1] = 1, [8 ... 9] = 10 };这样可以只初始化a[1], a[8], a[9]三个元素,其他元素的值为0,相当于:int a[10] = {0, 1, 0, 0, 0, 0, 0, 0, 10, 10};对于一个结构体:struct point { int x, y;};struct point p
阅读全文
摘要:Table of Contents1 CodeBlocks Nightly Build 版本 2 AutoReadOnly 3 Cscope 4 CPPCheck 5 Source Exporter 6 Doxyblock 7 Copy Strings to Clipboard 8 Cccc 9 Regular Expression tested 10 Help files 11 Header Fixup 12 Library Finder 13 DragScroll 14 Koder Query 15 Closed File List 16 HexEditor 1 CodeBlocks Ni
阅读全文
摘要:Windows下编译Boost并配置CodeBlocks和VisualStudioTable of Contents1 Must Know Before Installation2 编译参数含义 3 根目录下的文件 4 Windows 4.1 首先编译bjam 4.2 利用GCC编译器编译并配置CodeBlocks 4.3 利用MSVC编译器编译并配置Visual Studio 20084.4 命令行下调用5 测试代码 1 Must Know Before InstallationBoost官网Boost是个跨平台的库,完全编译(并不是说包含所有的包而是包含支持各种编译器的完整编译,例如GCC
阅读全文
摘要:函数typeid()返回值类型class type_info。其中type_info重载了操作符==, !=, =分别用来比较是否相等、不等、赋值。函数name()返回类型名称。class type_info {public: virtual ~type_info(); booloperator== (consttype_info& rhs) const; booloperator!= (consttype_info& rhs) const; boolbefore (consttype_info& rhs) const; constchar* name() const;
阅读全文
摘要:下面的代码可以说明一切:默认情况下模板内的基本类型(int float ...)是不会自动初始化为0的(不像一般函数/类中),要想实现其自动初始化可以在模板函数中T x = T(); 在类中可以在构造函数列表中: x(), y()....#include <iostream>using namespace std;template <typename T>void f(const T&){ // T x = T(); //对比可知,此时输出为0,而下面输出为一个未知数 T x; cout<<x<<endl;}template <ty
阅读全文
摘要:参考自《C++ Template》一书,解释得很详细,英语也比较简单应该可以看懂,如果看不懂得话可以找侯捷的翻译版本。 5.4 Template Template Parameters It can be useful to allow a template parameter itself to be a class template. Again, our stack class template can be used as an example. 模板参数列表里面可以存在模板,称之为模板参数模板。 To use a different internal container for st
阅读全文
摘要:参考《Effective C++》条款42:Understand the two meaning of typenameTable of Contents1 模板参数列表中与class关键字可相互替换 2 嵌套从属名称(nested dependent names) 3 是嵌套从属名称但不用加typename的两种情况 1 模板参数列表中与class关键字可相互替换template<typename T>template<class T>是一样的2 嵌套从属名称(nested dependent names)假如template内出现的名称如果依赖于某个模板参数,则称其
阅读全文
摘要:typedef int (*PF)(const char* , const char*);PF Register(PF pf);等价于:int (*Register (int (*pf)(const char *, const char *))) (const char *, const char *);Register是个函数指针,其参数是个返回int型的函数指针pf,pd参数为(const char*, const char*) Register函数指针的返回值又是个函数指针,返回值的函数指针的参数是(const char*, const char*),返回值是int 唉………… 用typ
阅读全文
摘要:Table of Contents1 模板参数推导在迭代器中的使用 2 模板参数引用与非引用的区别 1 模板参数推导在迭代器中的使用在算法中运用迭代器时,可能会用到其相应类型(associative type),即迭代器所指向对象的类别。但C++只支持sizeof(),并不存在typeof()之说(即使运用RTTI性质中的typeid()获得的也只是类型名称不能用来做变量声明之用)。为解决此问题,可以利用函数模板(function template)的参数推导(argument deduction)机制:template <class I, class T>void fun_imp
阅读全文
摘要:It is also possible to define a member template function. Let's look at an example and then walk through it:class PrintIt { public: PrintIt( ostream &os ) : _os( os ){} // a member template function template <typename elemType> void print( const elemType &elem, char delimi...
阅读全文
摘要:不翻译了,比较简单。这个 《ANSI/ISO C++ Professional Programmer's Handbook 》是这样说的 explicit Constructors A constructor that takes a single argument is, by default, an implicit conversion operator, which converts its argument to an object of its class (see also Chapter 3, "Operator Overloading"). Exa
阅读全文
摘要:/* auto_ptr是智能指引,可以自我销毁而不像new出来的对象一样需要调用delete销毁。 auto_ptr赋值用引起所有权的交接,作为函数参数或返回值都会引起所有权的交接。 auto_ptr必须显示初始化 auto_ptr<int> p(new int(43)) //ok auto_ptr<int> p = new int(43) //error auto_ptr<int> p; p = new int(43); //error p = auto_ptr<int>(43) //ok auto_ptr的函数: Type* release(
阅读全文
摘要:尽管函数名和参数列表都相同,void foo( ) const成员函数是可以与void foo( )并存的,可以形成重载! 我们假设调用语句为obj.foo(),如果obj为non-const对象,则调用foo()。如果obj为const对象,则调用foo()const。另外要注意,假如没有提供foo()const,则const obj调用foo()将会报错。但假如是没有提供foo(),则non-const obj调用foo()const是完全没有问题的。也就是说,non-const对象可以调用const函数,但const对象不能调用non-const函数.const关键字所起作用的本质,就是
阅读全文
摘要:1template specialization 模板特化一般情况下类模板定义如下:template<class Window, class Controller>class Widget{ ... 泛化实现代码 ...};特化是指把类模板中指定的class T变成具体的类型:class Widget<ModalDialog, MyController>{ ... 特化实现代码 ...};其中ModalDialog和MyController是你自己另外定义的类.有了这个Widget的特化定义之后,如果你以后定义了Widget<ModalDialog, MyCont
阅读全文
摘要:小端字节序x86系列是little endian是指在存储时低位放在低地址。大端字节序PowerPC是big endian存储时高位放在低地址。例如存储0x1234,12是高位,34是低位。big endian存储:内存地址 低->高存储内容 12 34little endian存储:内存地址 低->高存储内容 34 12程序验证当前使用CPU的字节序:使用普通方法:强制类型转化#include <stdio.h>int main(int argc, char *argv[]){ int num = 0; int *p = # *((char *)p)
阅读全文
摘要:很优秀的文章但不知哪位大神所写,多谢这位大神!一、初始化输入gdb进入gdb调试环境。或者直接输入gdb + progfile来加载文件。注意该文件是使用gcc(或g++)编译得到的。为了使 gdb 正常工作, 必须使你的程序在编译时包含调试信息,编译时必须使用-g参数来。或者进入gdb环境后,通过命令file + progfile来加载需要调试的可执行文件文件。查看源代码:list [函数名][行数]设置程序运行参数:set args二、暂停程序gdb可以使用几种方式来暂停程序:断点,观察点,捕捉点,信号,线程停止。当程序被暂停后,可以使用continue、next、step来继续执行程序。
阅读全文
摘要:#include <iostream>#include <cstring>class CTextBlock{public: std::size_t length() const;private: char * pText; // mutable关键字的作用:可以在const成员函数中修改const成员变量。 //mutable std::size_t textLength; //mutable bool lengthIsValid; std::size_t textLength; bool lengthIsValid;};s...
阅读全文


浙公网安备 33010602011771号