Compile Error When Using List of Pointers

hey people,

returning after a long time to C++ and I'm having trouble compiling this code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <list>

using namespace std;

class testing {
	int value;
	static list<int*> valueList;
	static int howmany; // all testings share this one variable
	int *valuePointer;
	public:
		testing(int n) {
			howmany++;
			value=n;
			valuePointer=&value;
			valueList.push_front(valuePointer);
			};
		static void 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.

Regards,
UM
does this fix it?
 
list<int*> testing::valueList;


it does, indeed. muchos gracias.

though, it now has exposed the fact that

cout << (*iterValueList) << endl;

prints the address rather than the value to which it points (which is surely why the * is there?)...?
to get your numbers, change the line to:
cout << *(*iterValueList) << endl;

Some of the things you have going in your code I am not familiar with.
ah, yeah, that does it.

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.
I have never seen how to use the list class; in particular, the line
static list<int*> valueList; ... the <int*> is foreign to me.

I'm pretty much a beginner myself, so I am not one to pass judgment on your style.
Topic archived. No new replies allowed.