Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!uunet!yale!cmcl2!andersnb From: andersnb@cmcl2.NYU.EDU (Brian Anderson) Newsgroups: comp.lang.c++ Subject: accessing static class members Keywords: g++, c++, static members Message-ID: <41398@cmcl2.NYU.EDU> Date: 11 Aug 89 04:02:38 GMT Followup-To: poster Organization: New York University, Ultracomputer project Lines: 64 I have a question about static class members. I'm not sure if I don't understand there use or if I have found some compiler bug. Here goes: I have two simple files and a header file as follows: --test.h---- class what { public: static int hold; friend int k(int); what(int i) {hold = i;}; inline int itis() {return hold;}; }; ------------ --test_1.cc- #include#include "test.h" extern int j(int); extern int k(int); main(){ what main_what(3); k(5); cout << main_what.itis() << " " << j(4) << " "<< k(5) << "\n"; } ------------ --test_2.cc- #include "test.h" int j(int i) { what j_what(i); return j_what.itis(); } int k(int i) { what::hold = i; return what::hold; } ----------- I tried this piece of code, both with "hold" as a private member and as a public member (this is why k() was declared as a friend). I would think that the output should be "5 5 5" since the call to k() would update the single static member. When "hold" was a private or public member the output was "4 4 5". Am I misusing static members? Please reply by email because our news machine is sick, Thanks, - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Brian G. Anderson | NYU Ultracomputer Research Project ||| 715 Broadway Rm. 1006 ||||| New York, NY 10003 ||||| (212) 998-3346 --- //\ --- arpa: andersnb@cmcl2 ----/ \---- uucp: {ihnp4,seismo}!cmcl2!andersnb ---- ----