undefined references with classes

Hi, I have a class like this

1
2
3
4
5
6
7
class Classer
{
static int count;
public:
Classer(){++count};
};


I noticed that that was garbage. How do I initialize a static variable... that suppose to keep track of how many of those class objects are created?

If I just initialize with default constructor... it would go abck to zero everytime an object was created.
nvm, i've figured this problem out by myself using the tutorial guide given on this site, page 99.

Thanks neway.
You have to initialize it in a source file somewhere:
1
2
3
4
/************** someFile.cpp ****************/
#include "theHeader.hpp"

int Classer::count = initializer value here;


You can initialize const static members of intrinsic type inside the class, but all others must be done in source code files.

[edit] Oh, you just beat me to it ;)
Last edited on
Topic archived. No new replies allowed.