【发布时间】:2013-06-24 22:16:33
【问题描述】:
/*
* CDummy.h
*/
#ifndef CDUMMY_H_
#define CDUMMY_H_
class CDummy {
public:
CDummy();
virtual ~CDummy();
};
#endif /* CDUMMY_H_ */
我读到不应在头文件中声明类变量。这对吗? 所以我在下面的cpp文件中声明:
/*
* CDummy.cpp
*/
#include "CDummy.h"
static int counter = 0; //so here is my static counter. is this now private or public? how can i make it public, i cannot introduce a public block here.
CDummy::CDummy() {
counter++;
}
CDummy::~CDummy() {
counter--;
}
使用此代码我无法从我的主程序访问类变量....
谢谢
【问题讨论】:
标签: c++ header class-variables