摘要:1.void operator= (const SomeClass& C) {....}2.SomeClass& operator= (const SomeClass& C) {....return *this;}结论:Both are legal and probably have the same performance.The problem with #1 is that it does't emulate the builtin operator=which is generally regarded as bad style.来源:http://by
阅读全文
摘要:看到这样一段代码:template<class_Ty> inline _Ty _FARQ *_Allocate(_SIZT _Count, _Ty _FARQ *){ //check for integer overflow if(_Count <= 0) _Count = 0; else if(((_SIZE)(-1)/_Count) < sizeof(_Ty)) _THROW_NCEE(std::bad_alloc, NULL); //allocate storage for _Count elements of type _Ty return((_Ty _FARQ
阅读全文
摘要:1) #define是预处理指令,在编译预处理时进行简单的替换,不作正确性检查,不关含义是否正确照样带入,只有在编译已被展开的源程序时才会发现可能的错误并报错。例如:#define PI 3.1415926程序中的:area=PI*r*r 会替换为3.1415926*r*r如果你把#define语句中的数字9 写成字母g 预处理也照样带入。2)typedef是在编译时处理的。它在自己的作用域内给一个已经存在的类型一个别名,但是You cannot use the typedef specifier inside a functiondefinition。3)typedef int * int_
阅读全文
摘要:来源自:http://www.cppblog.com/snailcong/archive/2009/03/16/76705.html程序说明一切://环境:vc6 + windows sp2//程序1#include <iostream>using namespace std;struct st1 { char a ; int b ; short c ;};struct st2{ short c ; char a ; int b ;};int main(){ cout<<"sizeof(st1) is "<<sizeof(st1)<
阅读全文