home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18381 < prev    next >
Encoding:
Text File  |  1992-12-23  |  1.8 KB  |  50 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!microsoft!wingnut!samk
  3. From: samk@microsoft.com (Sam Kho)
  4. Subject: Re: Access non-static data members in Motif callback functions.
  5. Message-ID: <1992Dec23.232305.5228@microsoft.com>
  6. Date: 23 Dec 92 23:23:05 GMT
  7. Organization: Microsoft Corporation
  8. References: <1992Dec21.144344.21100@asl.dl.nec.com>
  9. Distribution: global
  10. Lines: 38
  11.  
  12. In article <1992Dec21.144344.21100@asl.dl.nec.com> jng@aslslc71.asl.dl.nec.com (James Ng) writes:
  13. >
  14. >We use X11/R4 and Motif 1.1 for our GUI development. Our C++ compiler is
  15. >Object Center C++ (formerly called Saber C++). When we try to use a
  16. >non-static member function as a callback, sometimes nonstatic data members
  17. >get corrupted inside the callback function. Static data members seem to
  18. >maintain their integrity. Does anyone have similar experience or even
  19. >solution to solve the above problem? Any suggestion will be appreciated.
  20. >Suggestion can be mailed to jng@asl.dl.nec.com or posted if you prefer.
  21. >
  22. >James Ng
  23.  
  24. static data members r like global variables.  "this" is irrelevant.  non-
  25. static data members r like fields in a struct, where "this" is the pointer
  26. to the struct.  in a non-static member function, "this" is assumed to be
  27. the first hidden parameter, i.e.:
  28.  
  29.     class myclass
  30.     {
  31.     public:
  32.         void nonstatic    (int x);
  33.     };
  34.  
  35. is like:
  36.  
  37.     void myclass_nonstatic(myclass *this, int x);
  38.  
  39. now when Xt calls the callback, the first argument passed is the widget.
  40. my guess is u'r using the widget as "this"!  i'm surprised u'r even able
  41. to get non-corrupted values (probably that offset in the widget just happens
  42. to have the right value).
  43.  
  44. to verify, cast this into a widget inside the non-static member function,
  45. and do something with it (e.g. if it's a callback to a PushButton, change
  46. the label).
  47.  
  48.   - sam -
  49.  
  50.