#include <iostream>
#include <list>
usingnamespace std;
class testing {
int value;
static list<int*> valueList;
staticint howmany; // all testings share this one variable
int *valuePointer;
public:
testing(int n) {
howmany++;
value=n;
valuePointer=&value;
valueList.push_front(valuePointer);
};
staticvoid listing() {
list<int*>::iterator iterValueList;
for (iterValueList = valueList.begin();
iterValueList != valueList.end();
iterValueList++)
{
cout << (*iterValueList) << endl;
}
}
};
int testing::howmany=0;
static list<int*> valueList;
int main()
{
// create some objects of type 'testing', setting a value member to the given value
testing a(1),b(2);
// print the number of objects of type 'testing' and their values
testing::listing();
}
the following is the compile output:
1 2 3 4 5 6 7 8 9 10 11 12 13
**** Rebuild of configuration Debug for project Copy of Tutorial ****
**** Internal Builder is used for build ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -oExercise 10.o ..\Exercise 10.cc
..\Exercise 10.cc:39:2: warning: no newline at end of file
g++ -oTutorial.exe Exercise 10.o
Exercise 10.o: In function `ZN9__gnu_cxx13new_allocatorISt10_List_nodeIPiEEC2Ev':
C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/allocator.h:(.text$_ZN7testing7listingEv[testing::listing()]+0x14): undefined reference to `testing::valueList'
C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/allocator.h:(.text$_ZN7testing7listingEv[testing::listing()]+0x29): undefined reference to `testing::valueList'
C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/allocator.h:(.text$_ZN7testingC1Ei[testing::testing(int)]+0x2a): undefined reference to `testing::valueList'
collect2: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 7305 ms.
I get the feeling I'm making a really obvious mistake but I can't work it out for the life of me. All help much appreciated.
just out of interest, what are you not familiar with because this is very much my own code and if I'm doing something which could be construed as bad/non-standard coding, I'd quite like to know.