home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!microsoft!wingnut!samk
- From: samk@microsoft.com (Sam Kho)
- Subject: Re: Access non-static data members in Motif callback functions.
- Message-ID: <1992Dec23.232305.5228@microsoft.com>
- Date: 23 Dec 92 23:23:05 GMT
- Organization: Microsoft Corporation
- References: <1992Dec21.144344.21100@asl.dl.nec.com>
- Distribution: global
- Lines: 38
-
- In article <1992Dec21.144344.21100@asl.dl.nec.com> jng@aslslc71.asl.dl.nec.com (James Ng) writes:
- >
- >We use X11/R4 and Motif 1.1 for our GUI development. Our C++ compiler is
- >Object Center C++ (formerly called Saber C++). When we try to use a
- >non-static member function as a callback, sometimes nonstatic data members
- >get corrupted inside the callback function. Static data members seem to
- >maintain their integrity. Does anyone have similar experience or even
- >solution to solve the above problem? Any suggestion will be appreciated.
- >Suggestion can be mailed to jng@asl.dl.nec.com or posted if you prefer.
- >
- >James Ng
-
- static data members r like global variables. "this" is irrelevant. non-
- static data members r like fields in a struct, where "this" is the pointer
- to the struct. in a non-static member function, "this" is assumed to be
- the first hidden parameter, i.e.:
-
- class myclass
- {
- public:
- void nonstatic (int x);
- };
-
- is like:
-
- void myclass_nonstatic(myclass *this, int x);
-
- now when Xt calls the callback, the first argument passed is the widget.
- my guess is u'r using the widget as "this"! i'm surprised u'r even able
- to get non-corrupted values (probably that offset in the widget just happens
- to have the right value).
-
- to verify, cast this into a widget inside the non-static member function,
- and do something with it (e.g. if it's a callback to a PushButton, change
- the label).
-
- - sam -
-
-