Hello,
This is just about C++ and it's very simple.
I'm using QtCreator and MingW .
I define a new console project with the usual main.cpp and a class called myclass. The header is as follows:
class MyClass
{
public:
MyClass();
static int getInstanceCount(){return _instanceCount;}
private:
static int _instanceCount;
};
The code is as follows
#include "myclass.h"

MyClass::MyClass()
{
_instanceCount++;
}
The code of main is as follows:
#include <QtCore/QCoreApplication>
#include <iostream>
using namespace std;

#include "myclass.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
MyClass foo;
cout<<MyClass::getInstanceCount();
return a.exec();
}
The trouble is that this fails at link time with the repeated message that there is an
undefined reference to MyClass::_instanceCount

What have I done wrong and what can I do to fix it?
Thankyou.