Mail Archives: djgpp/1997/06/03/08:49:49
Hi All,
I have just been experimenting with C++ and have tried using the concept
of static class member variables, which according to my copy of
'The C++ Programming Language' 2ed by Bjarne Stroustrup is valid C++ syntax
-----> Example <-----
#include <stdio.h>
class clsTest
{
public :
static int instanceCount = 0;
public :
clsTest() { instanceCount++; };
~clsTest() { instanceCount--; };
virtual int getInstanceCount(void) { return instanceCount; };
};
main(int argc, char *argv[])
{
clsTest
*test;
printf("Instances (before) %d\n", clsTest::instanceCount);
test = new clsTest();
printf("Instances: %d\n", test->getInstanceCount());
delete test;
}
-----> Example <-----
However when I compile the example with gxx test.c -o test.exe, I get what
I think are LD errors:
-----> Errors <-----
C:\Temp>gxx test.cc -o test.exe
c:/djgpp/tmp\ccdaaaaa(.text+0x35):test.cc: undefined reference to
`clsTest::instanceCount'
c:/djgpp/tmp\ccdaaaaa(.text+0xc7):test.cc: undefined reference to
`clsTest::instanceCount'
c:/djgpp/tmp\ccdaaaaa(.text+0xe7):test.cc: undefined reference to
`clsTest::instanceCount'
c:/djgpp/tmp\ccdaaaaa(.text+0x116):test.cc: undefined reference to
`clsTest::instanceCount'
-----> Errors <-----
Could anybody explain what is happening here. I have looked in the FAQ
but couldn't spot anything.
Thanks in advance
John
________________________________________________________________
Parallax Solutions Ltd. Tel.: 01203 514522
Stonecourt, Fax.: 01203 514401
Siskin Drive, Web : http://www.parallax.co.uk/~johne
Coventry CV3 4FJ Mail: johne AT parallax DOT co DOT uk
________________________________________________________________
Remember:
There is no such thing as computer error, it's 100% YOUR fault
________________________________________________________________
- Raw text -