home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13499 < prev    next >
Encoding:
Text File  |  1992-09-10  |  1.5 KB  |  65 lines

  1. Path: sparky!uunet!gatech!concert!rutgers!news.columbia.edu!cunixb.cc.columbia.edu!kps
  2. From: kps@cunixb.cc.columbia.edu (Karthik P Sheka)
  3. Newsgroups: comp.lang.c++
  4. Subject: pointer typecasting question...
  5. Message-ID: <1992Sep10.210319.4450@news.columbia.edu>
  6. Date: 10 Sep 92 21:03:19 GMT
  7. Sender: usenet@news.columbia.edu (The Network News)
  8. Reply-To: kps@cunixb.cc.columbia.edu (Karthik P Sheka)
  9. Organization: Columbia University
  10. Lines: 52
  11. Nntp-Posting-Host: cunixb.cc.columbia.edu
  12.  
  13.  
  14. I'm working on a C++ program that is using a C package that is giving
  15. problems (The package was not meant to be used in C++):
  16.  
  17. One C call I make, CreateButton, takes as an arguement, a pointer to a
  18. function that takes one arguement and returns void:
  19.  
  20. void function(int arguement);
  21. main()
  22. {
  23.     CreateButton(function);
  24. }
  25.  
  26. When used in a C++ program, I want to send a pointer to an instance of a
  27. public function.  Unfortunately, this does not work:
  28.  
  29. class func1{
  30.   public:
  31.     function(int arguement);
  32. };
  33.  
  34. func1 *instance;
  35.  
  36. main()
  37. {
  38.   instance = new func1
  39.   CreateButton(func1->function);
  40. }
  41.  
  42.  
  43. What does work is(This is not usable by my program, because it does not
  44. call an instance of the class):
  45.  
  46. class func1{
  47.   public:
  48.     function(int arguement);
  49. };
  50.  
  51. main()
  52. {
  53.   void (*called_function)(int) = (void (*)(int))func1::function;
  54.  
  55.   CreateButton(called_function);
  56. }
  57.  
  58.  
  59. My question is, "How can I send a pointer to an instance of a function?"
  60.   (I tried
  61.     void (*called_function)(int) = (void (*)(int))instance->function; 
  62.   but that doesn't work.)
  63.  
  64. //Karthik Sheka
  65.