条款10 防止构造函数里的资源泄露条款20 协助编译器实现返回值优化条款22 考虑使用op=来取代单独的op运算符条款26 限制类对象的个数条款27 要求或禁止对象分配在堆上
转载 2015-11-15 13:49:00
101阅读
2评论
c++
c++
原创 2021-06-01 09:15:03
1232阅读
一本需要反复阅读的书
原创 2021-07-23 17:02:03
352阅读
基础议题条款1:仔细区别pointers和references首先你必须认知一点,没有所谓的 null reference。由于reference一定得代表某个对象,C++因此要求references必须有初值。Pointers和references之间的另一个重要差异就是,pointers可以被重新赋值,指向另一个对象,reference却总是指向(代表)它最初获得的那个对象。结论:当你知道你需
转载 2021-02-01 10:50:53
298阅读
2评论
人们有时好像喜欢故意使C 语言的术语难以理解。比如说new操作符(new operator)和operator new的区别。   当你写这样的代码:string *ps = new string("Memory Management");
原创 2023-08-09 11:07:04
57阅读
1 基础 ~~~~~~~ 1.1 指针和引用区别 ===================    1. 指针可以指向空值,引用不能指向空值    2. 指针定义时可以不初始化,引用定义时必须初始化    3. 指针可以被重新赋值指向另一个对象,而引用在初始化时被指定的对象,以后不能改变,但它和本体的值会因赋值而改变 &
原创 2013-03-26 07:31:59
632阅读
4 技巧 ~~~~~~~ 4.1 如何将构造函数和非成员函数虚拟化 =====================================    1. 虚拟构造函数是指能够根据输入给它的数据的不同而建立不同类型的对象的成员函数(不是构造函数!!).    2. 虚拟拷贝构造函数返回一个指针,指向调用该函数的对象的新拷贝.因此其名字通常为
原创 2013-03-26 07:35:51
602阅读
条款20 协助编译器实现返回值优化 当重载运算符的时候,比如+ - * / 这类运算符,该函数返回的值一定是个右值(即不能是引用),那么执行一次运算的开销可能会在临时对象上调用多次构造函数和析构函数,这笔开销还是很大的。现在的新编译器已经可以对这种情况进行优化了,甚至优化到连开销都没有,只是有...
转载 2015-11-16 18:36:00
120阅读
2评论
3 异常 ~~~~~~~ 3.1 防止构造函数在存在异常时发生资源泄露 =========================================    1. 如果你用对应的auto_ptr对象替代指针成员变量,就可以防止构造函数在存在异常时发生资源泄漏,你也不用手工在析构函数中释放资源,并且你还能象以前使用非const指针一样使用const指针,给其赋
原创 2013-03-26 07:34:18
596阅读
5 其他杂项 ~~~~~~~~~~~ 5.1 在未来时态下开发程序 =========================    1. 用C++语言自己来表达设计上的约束条件,而不是用注释或文档    2. 未来时态的考虑不是问一个类现在正被怎么使用,而是问这个类是被设计为怎么去使用的.    3. 未来时态的考虑只是简单
原创 2013-03-26 07:36:40
558阅读
Proxy classes allow you to achieve some types of behavior that are otherwise difficult or impossible to implement. Multidimensional arrays are one example, lvalue/rvalue differentiation is a second, suppression of implicit conversions (see Item 5) is a third. At the same time, proxy classes hav...
转载 2012-03-20 13:01:00
105阅读
2评论
TBD
转载 2012-03-16 13:02:00
135阅读
2评论
When you use smart pointers in place of C++'s built-in pointers (i.e., dumb pointers), you gain control over the following aspects of pointer behavior:Construction and destruction. You determine what happens when a smart pointer is created and destroyed. It is common to give smart pointers a def
转载 2012-03-15 14:33:00
267阅读
2评论
Let us assume, however, that you must implement your game in C++ — that you must come up with your own way of implementing what is commonly referred to as double-dispatching. (The name comes from the object-oriented programming community, where what C++ programmers know as a virtual function ca...
转载 2012-03-21 17:31:00
84阅读
2评论
2 运算符 ~~~~~~~~~ 2.1 谨慎定义类型转换函数 =========================    1. 有两种函数允许编译器进行隐式类型转换:       * 单参数构造函数(包括除了第一个参数,所有参数都有缺省值得情况)       *
原创 2013-03-26 07:32:57
497阅读
The contrast in performance between iostreams and stdio is just an example, however, it's not the main point. The main point is that different libraries offering similar functionality often feature different performance trade-offs, so once you've identified the bottlenecks in your software (
转载 2012-03-12 14:35:00
123阅读
2评论
Good software adapts well to change. It accommodates new features, it ports to new platforms, it adjusts to new demands, it handles new inputs. Software this flexible, this robust, and this reliable does not come about by accident. It is designed and implemented by programmers who conform to th...
转载 2012-03-22 10:40:00
60阅读
2评论
There are thus three primary ways in which passing an object to a function or using that object to invoke a virtual function differs from throwing the object as an exception. First, exception objects are always copied; when caught by value, they are copied twice. Objects passed to function para...
转载 2011-09-29 15:44:00
90阅读
2评论
The purpose of operator overloading is to make programs easier to read, write, and understand, not to dazzle others with your knowledge that comma is an operator. If you don't have a good reason for overloading an operator, don't overload it. In the case of &&, ||, and ,, it's di
转载 2011-06-11 11:16:00
177阅读
2评论
Tips 《Effective Java, Third Edition》一书英文版已经出版,这本书的第二版想必很多人都读过,号称Java四大名著之一,不过第二版2009年出版,到现在已经将近8年的时间,但随着Java 6,7,8,甚至9的发布,Java语言发生了深刻的变化。 在这里第一时间翻译成中文版。供大家学习分享之用。40. 始终使用Override注解Java类库包含几个注解类型。对于典型的
转载 2023-08-09 15:49:34
42阅读
  • 1
  • 2
  • 3
  • 4
  • 5