Effective of C++---改变旧有的C习惯 2013-01-03 13:20 174人阅读 评论(0) 收藏
case 1: using const and inline instead of #define
reason :when complier complain a error for "1.653", we may not realize it is a Macro.
1.how to define a const pointer?
const char* const authorName = "Deman Lu";
2.define a static const member in class.
we should define it bouth in class body and in cpp file .
3. may be you can use enum for a const member.
case 1.2 using inline function to define function.
template<class T>
inline const T& max(const T& a, const T& b)
{return a>b ? a:b;}
case 2: using <iostream> instead of <stdio.h> and <iostream.h>
operator>> and operator << can using int, double, sring by default.
case 3:using new and delete instead of malloc and free.
new and delete will call constructors and destructors.
case 4: using C++ annotation instead of C style
using // not /**/
版权声明:本文为博主原创文章,未经博主允许不得转载。
posted on 2013-01-03 13:20 Joyfulmath 阅读(95) 评论(0) 编辑 收藏 举报