#ifndef CHAP_8_H
#define CHAP_8_H
#include "iostream"
using namespace std;
class A
{
private:
int a;
static int count;
public:
static int public_count;
static void show();
};
int A::count=1;//静态数据成员的初始化需放在类外执行
int A::public_count=1;
void A::show()
{
cout<<"the number is :"<<count<<endl;
cout<<"the number is :"<<public_count<<endl;
//cout<<"a is :"<<a<<endl;//静态成员函数不能访问非静态数据成员,除非将对象作为参数传入,用对象访问非静态数据成员
}
#endif
// chap_8.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "chap_8.h"
int _tmain(int argc, _TCHAR* argv[])
{
A a;
//A::count++;//不能访问静态私有变量
A::public_count++;
A::show();
return 0;
}