2008-03-24

温故而知新 - static应用

关键字: 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 函数中要注意什么?
  1. ·不能有this 指针
  2. ·不能引用class中的非static成员(变量、成员)
  3. ·static的成员函数不能再声明成volatile或const
评论
发表评论

提醒: 该博客已发表在公共论坛,博客所有留言会成为论坛回贴,留言请注意遵守论坛发贴规则

您还没有登录,请登录后发表评论

xombat
搜索本博客
存档
最新评论