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

Date: Sat, 29 May 93 11:19:03 -0500
From: Tom Hite <mgx!thite AT uu DOT psi DOT com>
To: djgpp AT sun DOT soe DOT clarkson DOT edu, russ AT pta DOT pyramid DOT com DOT au
Subject: Re: I need some help with static members

>Hi,

[stuff deleted]

>>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?

Correct.  All you've done in the class declaration is specify that
somewhere there is a static variable that belongs to the class.

YOU have to instantiate that member variable in your class implementation
file (or at least somewhere):

// header file
class A
{
 private:
	static int m_nCount;

 public:
	 // other members and whatnot
};

------------

// CPP implementation file
int A::m_nCount = 0;

// other member variables and whatnot follow

--------

Thats it.  I hope this is clear...

Tom Hite
thite AT micrografx DOT com

- Raw text -


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