摘抄的笔记,很乱

来源:互联网 发布:手机怎么开通淘宝店 编辑:程序博客网 时间:2024/04/29 23:59
1.模板中不允许自动类型转换,每个参数必须完全匹配其类型。自动类型转换只用于普通函数。
2.当其他的条件都相同时,c++的重载机制会优先选择non-template function,而不选择由template function实例化的函数实体。然而,调用函数的时候也可以使用empty template argument list来告诉编译器只从template实例中选择被调用的对象。
3.对于class template而言,只有被使用到的成员函数才会被实例化。这样你可以实例化一个class template,而实例的类型可以不完全支持class template内与该类型有关的所有操作。
 
来看初始化列表:数据成员的声明操作都是在构造函数执行之前就完成了,在构造函数中往往完成的只是赋值操作,然而初始化列表直接是在数据成员声明的时候就进行了初始化,因此它只执行了一次copy constructor。再来看在构造函数中赋值的情况:首先,在构造函数执行前会通过default constructor创建数据成员,然后在构造函数中通过operator =进行赋值。因此它就比初始化列表多进行了一次函数调用。性能差异就出来了。但是请注意,如果你的数据成员都是基本类型的话,那么为了程序的可读性就不要使用初始化列表了,因为编译器对两者产生的汇编代码是相同的。
 
Ordinarily, single-parameter constructors should be explicit unless there is an obvious reason to want to define an implicit conversion. Making constructors explicit may avoid mistakes, and a user can explicitly construct an object when a conversion is useful.
 
ptrdiff_t
Machine-dependent signed integral type defined in cstddef header that is large enough to hold the difference between two pointers into the largest possible array.
 
If a function declaration does not specify an exception specification, the function can throw exceptions of any type.
 
 
  
fuzzy logic is a means of presenting problems to computers in a way akin to the way humans solve them." Zadeh later goes on to say that "the essence of fuzzy logic is that everything is a matter of degree.
 
 
The process of software development should be straightforward. First,you design the abstractions, from a careful consideration of the problem to be solved and its likely future variants. Then you develop its embodiments in code: the interfaces and modules, data structures and algorithms.
 
面向对象程序设计时一条常规的准则,最早是在Grady Booch那里听说的:“若设计过于复杂,就制作更多的对象”。(“制作更多的对象”经常等同于“添加另一个层次的迂回”)。一般情况下,如果发现一个地方充斥着大量繁复的代码,就需要考虑什么类能使它显得清爽一些。用这种方式整理系统,往往会得到一个更好的结构,也使程序更加灵活。 
原创粉丝点击