温故而知新 - static应用

1> A static data member can be of the same class type as that of which it is a member. a nonstatic data member is restricted to being decleared as a pointer or a reference to an object of its class.
class Bar{
private:
static Bar mem1; //ok
Bar *mem2; //ok
Bar mem3; //error
}


2> static成员变量能够作为当前class的成员函数的默认参数,但是non-static则不可以

3>对于static成员函数的声明和定义,在class 中声明时要标注static关键字,而在class外部定义时,一定不要写static.

4>static 函数中要注意什么?
[list=1]
[*]·不能有this 指针
[*]·不能引用class中的非static成员(变量、成员)
[*]·static的成员函数不能再声明成volatile或const
[/list]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值