随笔分类 -  C/C++基础

基础知识乃为万古长空。须用勤平心,参悟牢记。
【操作符重载】等号的两种形式
摘要: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 阅读全文

posted @ 2012-05-24 11:25 LateStop 阅读(2384) 评论(0) 推荐(0)

#define _FARQ的解释
摘要:看到这样一段代码: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 阅读全文

posted @ 2011-10-27 14:59 LateStop 阅读(5690) 评论(0) 推荐(1)

#define与typedef的区别
摘要: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_ 阅读全文

posted @ 2011-10-27 14:43 LateStop 阅读(275) 评论(0) 推荐(0)

内存对齐的讲解
摘要:来源自: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)< 阅读全文

posted @ 2011-10-21 10:50 LateStop 阅读(278) 评论(0) 推荐(0)

导航