home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18480 < prev    next >
Encoding:
Text File  |  1992-12-16  |  1.1 KB  |  66 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!yale!gumby!destroyer!cs.ubc.ca!newsserver.sfu.ca!sfu.ca!wong
  3. From: wong@fraser.sfu.ca (Sam S. Wong)
  4. Subject: Re: Need help: array of pointers to member functions C++.
  5. Message-ID: <wong.724531626@sfu.ca>
  6. Sender: news@sfu.ca
  7. Organization: Simon Fraser University, Burnaby, B.C., Canada
  8. References: <wong.724526569@sfu.ca>
  9. Date: Wed, 16 Dec 1992 18:47:06 GMT
  10. Lines: 54
  11.  
  12. Never mind.  I figured out the solution.
  13. I have to cast the the address of that member.  Its ugly but it works.
  14.  
  15. The Solution is:
  16.  
  17. >-------------------------------------
  18.  
  19.  
  20. >class dummy {
  21. > public:
  22. > int hello(void);
  23. >};
  24.  
  25. >int just_hello (void);
  26.  
  27. >dummy dumb;              
  28. >int (*fnptr[10])(void);
  29.  
  30.  
  31. >main()
  32. >{ 
  33. >  dumb.hello();
  34. >  fnptr[1] = just_hello;
  35. >  (*fnptr[1])();
  36. >  fnptr[1] = (int (*)(void))&dummy::hello;  // cast it this way or
  37. >  fnptr[1] = (int (*)(void))&dumb.hello;    // this way.
  38. >  (*fnptr[1])();
  39. >}
  40.  
  41.  
  42. >int dummy::hello (void)
  43. >{
  44. >  printf ("\nhello");
  45. >}
  46.  
  47.  
  48. >int just_hello (void)
  49. >{
  50. >  printf ("\njust_hello");
  51. >}
  52.  
  53.  
  54. >-----------------------------------------------------
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.