home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / gnu / gcc / help / 1824 < prev    next >
Encoding:
Text File  |  1992-07-31  |  1.3 KB  |  64 lines

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!usc!news.bbn.com!kirin!mfausett
  2. From: mfausett@bbn.com (Mark Fausett)
  3. Newsgroups: gnu.gcc.help
  4. Subject: static instance variables in class not visible
  5. Date: 31 Jul 92 18:28:21 GMT
  6. Lines: 53
  7. Distribution: world
  8. Message-ID: <mfausett.712607301@kirin>
  9. NNTP-Posting-Host: kirin.bbn.com
  10.  
  11. Curious;  If I declare a static instance variable in a class, for example:
  12. //class.H:
  13. class Stat {
  14. protected:
  15.   int nonStat;
  16.   static int isStat;
  17. public:
  18.   Stat(int n, int s){
  19.     nonStat=n;
  20.     isStat=s;
  21.   }
  22.   int getStatVar();
  23.   void setStatVar(int val);
  24. };
  25.  
  26. and then in class.C attempt to use it:
  27.  
  28. //class.C
  29. #include "class.H"
  30.  
  31. int Stat::getStatVar(){
  32.   return isStat;
  33. }
  34.  
  35. void Stat::setStatVar(int val){
  36.   isStat = val;
  37. }
  38.  
  39. #include <iostream.h>
  40. main(int argc, char *argv[]){
  41.   Stat j(1,2);
  42.   Stat k(1,5);
  43.   cout << j.getStatVar() <<endl;
  44.   j.setStatVar(4);
  45.   cout << k.getStatVar() <<endl;
  46. }
  47.  
  48. I get linking problems like this:
  49.  
  50. gcc -o class class.C -lg++ld: Undefined symbol 
  51.    __4Stat$isStat 
  52. collect: /usr/bin/ld returned 2 exit status
  53.  
  54. Compilation exited abnormally with code 1 at Fri Jul 31 11:35:32
  55.  
  56. In particular, I'm not use GNU ld.  This is on a Sun4m, but same thing 
  57. happens on my NeXT as well.
  58. Do I misunderstand static class variables, will it work with GNU ld, or ???
  59.  
  60. Thanks!
  61.  
  62. Mark Fausett
  63. mfausett@bbn.com 
  64.