c++
c++
原创 2021-06-01 09:15:03
1232阅读
基础议题条款1:仔细区别pointers和references首先你必须认知一点,没有所谓的 null reference。由于reference一定得代表某个对象,C++因此要求references必须有初值。Pointers和references之间的另一个重要差异就是,pointers可以被重新赋值,指向另一个对象,reference却总是指向(代表)它最初获得的那个对象。结论:当你知道你需
转载 2021-02-01 10:50:53
298阅读
2评论
条款20 协助编译器实现返回值优化 当重载运算符的时候,比如+ - * / 这类运算符,该函数返回的值一定是个右值(即不能是引用),那么执行一次运算的开销可能会在临时对象上调用多次构造函数和析构函数,这笔开销还是很大的。现在的新编译器已经可以对这种情况进行优化了,甚至优化到连开销都没有,只是有...
转载 2015-11-16 18:36:00
120阅读
2评论
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评论
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评论
Make sure the C++ and C compilers produce compatible object files.Declare functions to be used by both languages extern "C".If at all possible, write main in C++.Always use delete with memory from new; always use free with memory from malloc.Limit what you pass between the two languages to
转载 2012-03-26 12:04:00
106阅读
2评论
Effective C++ 55 Specific Ways to Improve Your Programs and design1、让自己习惯C++。 Accustoming yourself to C++条款01:视C++为一个语言联邦。 View C++ as a federation of languages.条款02:尽量以const enum inline 替换 #define。 Prefer const,enum and inline to #define.条款03:尽可能使用const。 Use const whenever possible.条款04:确定对象被使用之前已被
转载 2013-10-01 00:57:00
157阅读
最近又重新看了Effective C+,不过到现在还是有好多地方不懂的,先记下笔记,待用的时候再细细琢磨。 条款1:尽量用const和inline而不用#define 这个条款最好称为:“尽量用编译器而不用预处理”,因为#define经常被认为好象不是语言本身的一部分。 用const的好处是,调试时,可以直接获取变量,而非定义的数字,这个在使用gdb跟踪代码的时候很有用,比如#define N
转载 2009-11-04 15:31:00
121阅读
2评论
static_cast has basically the same power and meaning as the general-purpose C-style cast. It also has the same kind of restrictions. For example, you can't cast a struct into an int or a double into a pointer using static_cast any more than you can with a C-style cast. Furthermore, static_cast c
转载 2011-06-03 14:32:00
108阅读
2评论
0.1.守则01:把C++看做一个语言的集合,而不是单一的语言 早期的C++只是叫"C with classes",但发展到今天已经成为一个多重泛型编程语言(Multi-paradigm programming language),它具有4种“子语言”:C 面向对象的C++ 模板C++ STL 0.
转载 2013-08-01 23:57:00
163阅读
2评论
一本需要反复阅读的书
原创 2021-07-23 17:02:03
352阅读
The rules for C++ allow compilers to optimize temporary objects out of existence. As a result, if you call operator* in a context like this,Rational a = 10;Rational b(1, 2);Rational c = a * b; // operator* is called here your compilers are allowed to eliminate both the ...
转载 2012-03-09 14:08:00
95阅读
2评论
There is a common theme running through this Item, and that's that greater speed can often be purchased at a cost of increased memory usage. Keeping track of running minima, maxima, and averages requires extra space, but it saves time. Caching results necessitates greater memory usage but reduce
转载 2012-03-07 12:59:00
71阅读
2评论
It's important to keep a balanced view of exception specifications. They provide excellent documentation on the kinds of exceptions a function is expected to throw, and for situations in which violating an exception specification is so dire as to justify immediate program termination, they offe.
转载 2011-09-30 11:41:00
70阅读
2评论
  • 1
  • 2
  • 3
  • 4
  • 5