C++咬文嚼字-'Pointer Trick'
晚上饭后抽空看了看如何实现一个内存管理器,涉及内存操作必定少不了指针,恰研究到offsetof这个operator,也看了它的实现,顿有所悟。 ...
晚上饭后抽空看了看如何实现一个内存管理器,涉及内存操作必定少不了指针,恰研究到offsetof这个operator,也看了它的实现,顿有所悟。 ...
关于Functions,Bjarne Stroustrup在’The C++ Programming Language’一书中是这么开篇的:‘The typical way of getting something done in a C++ program is to call a function to do it.’;另外他还阐述了一个使用Functions的原则:‘A function cannot be called unless it has been previously declared.’。 ...
Cast也被称为"Explicit Type Conversion",即显式类型转换,在传统C中强制转型(cast)只有一种语法形式(T)e。Bjarne Stroustrup在’The Design and Evolution of C++’(以后称作D&E)一书的14.3小节开始就说了’无论是从语法还是从语义上, Cast都是C++里最难看的特征之一’,所以他要为cast提供A New Cast Notation. ...
C程序员和C++程序员在声明空指针时做法常常是不相同的。 C程序员常常如下做: int *ptr = NULL; C++程序员则是听从Bjarne Stroustrup或者其他C++大师的教诲,坚定地如下做: int *ptr = 0; ...
晚上无意翻看Bjarne Stroustrup的’The C++ Programming Language Special Edition’(英文版)第94页,章节5.4 Constants一节,看到这么一句原文’C++ offers the concept of a user-defined constant, a const, to express the notion that a value doesn’t change directly.‘字眼就在directly上,既然不能directly change,那我试试indirectly change。 ...