本书内容取自作者博客的gotw栏目,即Guru of the Week,通过问答方式更深入地挖掘C++语言特性适用...[作者空间]
问题 如何改进这个转呼叫函数 解答 有两个主要改进可以使这个函数更高效,第一个应该总被采用,第二个需要权衡传参时用...[作者空间]
问题 如果没有bool类型,能用已有的数据类型达到相同效果吗? 解答 不能,bool型和true,false无法通...[作者空间]
建议总是使用T t(u)形式,因为只要可以用T t = u的地方都可以用它,而且它还可以支持多个参数[作者空间]
这段代码使徒用拷贝构造操作来实现拷贝赋值操作,以避免在两个地方重复相同代码,但存在许多问题会切割对象,如果T是一个...[作者空间]
#2处代码是安全合法的,但函数作为一个整体它不是异常安全的,且这是一个坏习惯 在调用T(2)时,T的构造函数有抛出...[作者空间]
把string作为C风格的const char*来访问通常很有用,实际上string有一个返回cosnt char...[作者空间]
问题 找出下列代码中与内存有关的错误 解答 B的delete有第二个参数而D没有,这是出于个人喜好,两种写法都可行...[作者空间]
C++有几个不同的内存区域,用来存储对象或其他类型的值,每一个区域有其各自的特点 常量数据区(const data...[作者空间]
Class定义:一个Class描述了一组数据及操作这些数据的函数 接口原则:对于一个类X,所有的函数,包括非成员函...[作者空间]
问题 下面代码调用的是哪个函数 解答 1调用的是它自己,并且是无穷递归,因为B没有using namespace ...[作者空间]
malloc()和new()调用开销很大,下面代码最初在class Y中设计了一个类型X的成员 这个class Y...[作者空间]
如果类定义中的任何部分被改变,这个类的使用者必须重新编译代码,为了降低依赖性,一种常见技术是利用一个不透明指针隐藏...[作者空间]
问题 下面的头文件中哪些#include语句可以在不对程序产生副作用的前提下去掉 解答 可以直接去掉的iostre...[作者空间]
问题 耦合关系要尽量减少,如果class和class之间有多种方式表达,使用关系最弱的一种,继承是C++所能表达的...[作者空间]
问题 资源管理软件往往需要对某个表格中的所有记录做操作,先执行一次只读动作走一遍表格,放进cache,然后再进行修...[作者空间]
问题 一个网络程序有两种通信行为,每种行为有自己的协议规定,两个规定之间有一些相似之处,某程序员设计如下,将共同运...[作者空间]
问题 下列代码期望打印出什么结果,实际打印结果是什么 解答 delete pb不安全,因为Base没有虚析构函数 ...[作者空间]