delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1993/05/29/02:57:51

From: Russell Day <russ AT pta DOT pyramid DOT com DOT au>
Subject: I need some help with static members
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Date: Sat, 29 May 1993 16:28:04 +1000

Hi,
	I am new to c++, and I am having real problems with static members
	in that I cant work out how to get gcc to create the static
	element.  All the books I have seem to treat static members as
	trivial, but maybe they arent.

	This is the error:

	x.o: Undefined symbol __5thing$i referenced from text segment

	It seems fairly obvious that gcc hasnt allocated the data
	object, so what do I have to do to make it work?

	I would expect that the constructor is not necessary this
	example.  It is there because I thought that the compiler
	might not create the variable until it was actually newed.

	Thanks for you patience.
	I dont think I like c++ very much!  Maybe I'm getting too old
	for this business!
Russ
-----------------------------------------------------------------------------
class thing {
public:
	thing();
	static int i;
};

thing::thing()
{
	i=-1;
}


main ()
{
	thing* x = new thing();
	thing::i = 1;
}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019