Mail Archives: djgpp/1993/05/29/02:57:51
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 -