home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!max.fiu.edu!serss0!feathers
- From: feathers@serss0 (Michael Feathers)
- Newsgroups: comp.lang.c++
- Subject: Re: More Gnu C++ fun
- Message-ID: <C06HCB.H4M@fiu.edu>
- Date: 1 Jan 93 13:55:23 GMT
- References: <1992Dec30.195714.9824@adimail.uucp>
- Sender: news@fiu.edu (Usenet Administrator)
- Organization: Florida International University, Miami
- Lines: 55
-
- In article <1992Dec30.195714.9824@adimail.uucp> tel@adimail.uucp (Terry Monks) writes:
- >This minimal program
- >
- >
- >class node
- >{
- >public:
- > static int level;
- >
- > node(){};
- >};
- >
- >main()
- >{
- > node::level=1;
- >}
- >
- >
- >compiles and links fine using the AT&T compiler from Sun, but will not link
- >under Gnu c++. (sparc-sun-sunos.4.1)
- >
- >I get the message
- >ld: Undefined symbol
- > __4node$level
- >
- >
- >Any clues?
- >
- >--
- >Terry Monks Automata Design Inc (703) 742-9400
-
- I think that the problem may be that you don't have a definition of
- node::level in your program. It is declared within the class but
- technically, no data is allocated.
-
- Imagine if it were. Every file that you include your class declaration
- within would have a static instance of node::level. Some implementations,
- I suppose, will create the single instance you want in one particular file
- behind the scenes, but many compilers force you to define all your class
- static variables outside class declarations. In fact, I think the ARM
- requires this now.
-
- For your program, you can achieve the effect you want by placing the
- following line before main ():
-
- int node::level = 1;
-
- You can delete the initialization within main also. Since node::level is
- truly static, you can give it that initial value in its definition.
-
- Michael C. Feathers
-
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- My opinions are not those of any organization because organizations do
- not have opinions.
-