Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!cs.utexas.edu!rutgers!mcnc!unccvax!cs00wsc From: cs00wsc@unccvax.UUCP (Shiang Chin) Newsgroups: comp.lang.c++ Subject: C++ and SunView Keywords: C++, SunView Message-ID: <1804@unccvax.UUCP> Date: 23 Jan 90 06:48:24 GMT Distribution: usa Organization: Univ. of NC at Charlotte, Charlotte, NC Lines: 44 I have a problem when I create applications using C++ and SunView. For example, If I define a class: Class A: private: int a; ... public: A(); m1() { printf("%d\n",a);}; ... ~A(); }; and create a window with some command buttons by using SunView library. I assigned the method 'a()' to one of the command button as a called back notify procedure. Assumming the value stored in the variable 'a' now is 100, when I clicked the mouse on that command button the value printed out should be '100', but the value I got was not correct. After many tries, I defined a global variable: ... A* x; .... and then redefined the class definition: Class A: private: int a; ... public: A() { x = this;}; m1() {printf("%d\n",x->a);}; .... ~A() } Finally, I got the right value. Does any one know why? Thanx a lot. Wen S. Chin at UNC Charlotte