Timothy

链接

《More Exceptional C++》------ ( 2 )

《More Exceptional C++》------ ( 3 )

Timothy posted @ 2010年9月03日 22:42 in Reading Notes , 1869 阅读

 

条款29:auto_ptr
(1):auto_ptr不可用于数组情形.因为它删除内部指针时, 调用delete p,不会delete[] p.( 不要使用auto_ptr<T> t[n] )
(2):C++规定, 0长度数组合法, new T[0], 不会返回NULL, 返回数组地址,只是此数组没有任何元素可以被访问. (0长度数组依然不可以搭配auto_ptr)
 
条款30:智能指针的问题之一
(1):当类含有其他类指针时,注意拷贝问题,注意多次删除问题.
(2):用auto_ptr来包装这个指针,可以来内存分配和释放上有些许便利,但是对于拷贝和赋值依然存在问题.
 
条款31:智能指针问题之二
 
 
条款32:函数指针
(1):用代理类(重载向函数指针的类型转换 )实现 返回指向自己的函数指针.
	class CFuncPtrHelp;
typedef CFuncPtrHelp ( *FuncPtr ) ( void );

class CFuncPtrHelp
{
public:
	CFuncPtrHelp( FuncPtr p ) : m_pFunc( p ) {}
	operator FuncPtr() { return m_pFunc; }
private:
	FuncPtr m_pFunc;
};

CFuncPtrHelp Func()
{
	//other useful operation
	return Func;
}

int _tmain(int argc, _TCHAR* argv[])
{
	CFuncPtrHelp ptr = Func();
	ptr();

	system( "Pause" );
	return 0;
}

 

(2):typedef不能递归定义.
 
条款33:模拟嵌套函数
(1):嵌套类:定义在一个类内部的类,可以通过public, private等约束实现类的访问权限控制. 局部类:定义在函数内部的类,只对此函数可见,且不可用于模板参数.
(2):
 
条款34:预处理宏
(1):预处理宏的用处: a),预防头文件的多次包含 b),编译器预处理特性,_LINE_, _FILE_
c),条件编译( #ifdef __DEBUG ) d)去掉一些警告
 
条款35:宏定义
(1):宏常见错误: a),不要忘记给参数加上括号 b)不要忘记给展开式加上括号  c)注意多参数运算的问题  d)避免名字冲突,特别是和库中的函数等 
(2):其他宏需要注意到问题: a), 宏不可递归 b)宏没有地址 c)宏有碍调试
 
 
条款36:初始化
(1):变量初始化尽量使用 T t( u ), 而不是 T t = u.
 
条款37:前置声明
 
条款38:typedef
条款39:using和名字空间
条款40:名字空间使用
Avatar_small
Assam HSLC Evs Quest 说:
2022年9月30日 01:11

Every student of Assam Government and Private school class 10th standard student can download SEBA Question Paper for EVS by expert reference to guessing important questions for all chapters of EVS to all mediums of Hindi, English, Assamese, Bengali, Bodo, Manipuri, Garo, Nepali Medium general, Assam HSLC Evs Question Paper curriculum and vocational course students to the academic year of 2023.very student of Assam Government and Private school class 10th standard student can download SEBA Question Paper for EVS by expert reference to guessing important questions for all chapters of EVS to all mediums


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter