Hi, as a beginner of C++ I found the C++ Language Tutorial on this site is extremely helpful. As I progress through the tutorial, I seemed to get stuck at the Classes (II) section with these lines of code: (the output is 7,6)
// static members in classes
#include <iostream>
using namespace std;
class CDummy {
public:
static int n;
CDummy () { n++; };
~CDummy () { n--; };
};
int CDummy::n=0;
int main () {
CDummy a;
CDummy b[5];
CDummy * c = new CDummy;
cout << a.n << endl;
delete c;
cout << CDummy::n << endl;
return 0;
}