home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12659 < prev    next >
Encoding:
Text File  |  1992-08-20  |  2.4 KB  |  75 lines

  1. Newsgroups: comp.lang.c++
  2. From: nikki@trmphrst.demon.co.uk (Nikki Locke)
  3. Path: sparky!uunet!pipex!demon!trmphrst.demon.co.uk!nikki
  4. Distribution: world
  5. Subject: Re: help!!!
  6. References: <1992Aug18.063338.21333@debbie.cc.nctu.edu.tw>
  7. X-Mailer: cppnews $Revision: 1.14 $
  8. Organization: Trumphurst Ltd.
  9. Lines: 61
  10. Date: Thu, 20 Aug 1992 16:29:08 +0000
  11. Message-ID: <714353348snx@trmphrst.demon.co.uk>
  12. Sender: usenet@gate.demon.co.uk
  13.  
  14.  
  15. In article <1992Aug18.063338.21333@debbie.cc.nctu.edu.tw> cp79111@csie.nctu.edu.tw (Kuo-Ping Hsu) writes:
  16.  
  17. >          setvect(com_irq,&comm::NewIRQ);
  18. >                          ^^^^^^^^^^^^^
  19. >     But the compiler reports a following error :
  20. >          Error : Connot convert 'void (far interrupt comm::*)()'
  21. >                  to 'void (interrupt far *)(...)'
  22. If I had a dollar for every time I had seen this question asked (AND 
  23. answered) on the net, I'd be a rich man.
  24.  
  25. I take it you do not have access to any textbooks on the C++ language, or 
  26. to the excellent C++ FAQ (which is available for public ftp from such 
  27. sites as uu.net). If you have, I suggest you try reading them !
  28.  
  29. They will tell you (much more clearly than I am about to) that a member 
  30. function is an entirely different thing to a regular function. A member 
  31. function can only be called for a particular object ...
  32.  
  33. class Base {
  34.     int i;
  35. public:
  36.     Base(int j = 0) : i(j) {}
  37.     void bFunction();
  38.     };
  39.  
  40. void Base::bFunction()
  41. {
  42.     cout << "Base::bFunction " << i << "\n";
  43. }
  44.  
  45. void gFunction()
  46. {
  47.     cout << "gFunction\n";
  48. }
  49.  
  50. main()
  51. {
  52.     Base b;
  53.     
  54.     b.bFunction();        // call bFunction for object b
  55.     gFunction();        // regular function doesn't need an object
  56.     bFunction();        // ERROR - no Base object supplied
  57.                 // How is bFunction going to print this->i
  58.                 // when it doesn't have a this ?
  59.     return 0;
  60. }
  61.  
  62. So, obviously, your interrupt handler can't call a member function, 
  63. because it doesn't have an object to call it for.
  64.  
  65. The usual solution to this problem is to make the callback function either
  66. global (like you would have done in good ole C) or a static member of your
  67. class (a static member does not need an object).
  68. ---
  69. Nikki Locke              |                        | nikki@trmphrst.demon.co.uk
  70. Trumphurst Ltd.          | Tel: +44 (0)691-670318 | nikki@cix.compulink.co.uk
  71. PC and Unix consultancy  | Fax: +44 (0)691-670316 | nikki@kewill.co.uk
  72. trmphrst.demon.co.uk is NOT affiliated with ANY other sites at demon.co.uk.
  73. Demon.co.uk is a dial-up subscription access point to the Internet.
  74.