cs00wsc@unccvax.UUCP (Shiang Chin) (01/23/90)
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
dog@cbnewsl.ATT.COM (edward.n.schiebel) (01/25/90)
From article <1804@unccvax.UUCP>, by cs00wsc@unccvax.UUCP (Shiang Chin): > I have a problem when I create applications using > C++ and SunView. For example, If I define a class: > > [Class A with member function int a(); declared ] > > 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. You cannot do this. When SunView calls (), it does not know what A to call it with. Remember, a() as a member function is called as anA.a(). SunView is passing its own parameters in (I think a notify procedure is called with a Panel_item and an Event*). > 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. It guess was just (a lack of) luck that the program didn't core dump. When SunView called a(), there is no 'this'. > Wen S. Chin at UNC Charlotte Ed Schiebel AT&T Bell Laboratories dog@vilya.att.com