现在的位置: 首页 > 综合 > 正文

静态成员函数

2017年12月27日 ⁄ 综合 ⁄ 共 335字 ⁄ 字号 评论关闭

#include <iostream>
using namespace std;
class A
{
public:
 void static show(){cout<<A::n<<endl;n++;}
 void get(){cout<<n<<endl;}
/*
 类中任何成员函数都能访问静态成员
 静态成员函数不能直接访问非静态成员
 静态成员函数不能被说明为虚函数
*/
private:
 static int n;
 int m;
};
class B:public A
{
 
};
int A::n=0;
int main()
{
/*
 for (int i=0;i<5;i++)
 {
  A::show();
  cout<<endl;
 }
*/
 A::show();
 A a;
 a.get();
 B::show();
 return 0;
}

抱歉!评论已关闭.