2009-11-25
来源:互联网 发布:博奥计价软件 编辑:程序博客网 时间:2024/05/21 17:21
1、静态成员变量为const int 型时,可以直接在类体中初始化
这个功能可以用在定义一个数组
Integral const static Members Are Special
Ordinarily, class static members, like ordinary data members, cannot be initialized
in the class body. Instead, static data members are normally initialized when they
are defined.
One exception to this rule is that a const static data member of integral type can be
initialized within the class body as long as the initializer is a constant expression:
class Account {
public:
static double rate() { return interestRate; }
static void rate(double); // sets a new rate
private:
static const int period = 30; // interest posted every 30 days
double daily_tbl[period]; // ok: period is constant expression
};
A const static data member of integral type initialized with a constant value is a
constant expression. As such, it can be used where a constant expression is required,
such as to specify the dimension for the array member daily_tbl.
2、使用容器时,先声明一个空容器,以后当需要时再往里面插入值效率更高(省了拷贝构造函数一步)
As a general rule (Section 9.1.1, p. 307), unless you intend to use the default initial
value of the container elements, it is more efficient to allocate an empty container and
add elements as the values for those elements become known
3、拷贝、赋值、析构函数关系
A useful rule of thumb is that if a class needs a destructor, it will also need the
assignment operator and a copy constructor. This rule is often referred to as the Rule
of Three, indicating that if you need a destructor, then you need all three copy-control members.
4、类中数据成员初始化顺序是按照它们在类中声明顺序,析构时则相反
- 2009-11-25
- 2009-11-25
- 2009-11-25,2009-6-14
- 我的异常网 -异常汇总2009-11-25
- 我的异常网 -异常汇总2009-11-25
- 2009年11月25日(MySQL_2)
- Autohotkey 我的常用快捷键 2009-11-25 10:41:00
- Java中Scanner类的用法 (2009-08-11 01:27:25)转载
- 2009-07-25
- 2009-9-25
- 2009-9-25
- 2009-02-11
- WED MAR 11,2009
- MON MAY 11,2009
- 2009-06-11
- 2009-07-11
- 2009-08-11
- 2009-8-11
- Test subject
- 网页中图片如何应用CSS的滤镜的效果
- 如何停止拖延
- Web开发资源站点
- 对北大心底里怀着崇拜之情
- 2009-11-25
- 向Oracle插入timestamp类型字段
- Delphi中在窗体标题栏画自定义文字
- PE文件格式详解
- 盛大收购酷6感想
- 文件过滤器写法
- 网站被挂马怎么办呢?如何防止网站被挂马?
- 时间管理的 8 个建议
- shell中的单引号字符' 双引号字符" 反斜杠字符/ 反引号字符`