home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / sgi / 11548 < prev    next >
Encoding:
Text File  |  1992-07-28  |  1.8 KB  |  62 lines

  1. Xref: sparky comp.sys.sgi:11548 comp.lang.c++:11702
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!ucbeh.san.uc.edu!uceng.uc.edu!babbage.ece.uc.edu!snert.ece.uc.edu!tmcbraye
  3. Newsgroups: comp.sys.sgi,comp.lang.c++
  4. Subject: C++ member pointer error
  5. Message-ID: <1992Jul28.184745.2854@babbage.ece.uc.edu>
  6. From: tmcbraye@snert.ece.uc.edu (Tim McBrayer)
  7. Date: Tue, 28 Jul 1992 18:47:45 GMT
  8. Sender: root@babbage.ece.uc.edu (Operator)
  9. Organization: Unversity of Cincinnati, ECE Dept
  10. Nntp-Posting-Host: snert.ece.uc.edu
  11. Lines: 49
  12.  
  13. I'm trying to initialize a pointer to a class method and then call a function
  14. through said pointer.  I'm working in C++ on a SGI IRIS.  As far as I can
  15. tell, I'm accessing the pointer properly, according to Stroustrup's book.
  16. However, when I compile with "CC junk.cc", I get:
  17.  
  18. "junk.cc", line 21: error:  object missing in call through pointer to
  19. member function
  20.  
  21. The most frustrating part of this is that the code works under g++ on a 
  22. Sparcstation.  Are there any known bugs with SGI C++ with IRIX 4.0.1? Does
  23. anyone have any idea what 'object' is being referred to in the error
  24. message?
  25.  
  26. Example code follows.
  27.  
  28. #include <iostream.h>
  29.  
  30. class V{
  31. public:
  32.   int i;
  33.   V() { i = 0;};
  34.   void run();
  35.   char * print(int x) {cout << "x is " << x << endl; return "Foo!";};
  36. };
  37.  
  38. struct E {
  39.   typedef char * (V::*fnptr)(int);
  40.   fnptr fn;
  41.   E() { fn = 0;};
  42. };
  43.  
  44. void V::run() {
  45.   E e;
  46.   e.fn = (fnptr) &V::print;
  47.   i = 42;
  48.   cout << (e.fn)(i) << endl;  //ERROR: (*(e.fn))(i) gives the same error
  49. };
  50.  
  51. int main(){
  52.   V v;
  53.   v.run();
  54.   cout << v.print(5) << endl;
  55. }
  56.  
  57. Thanks in advance for any and all help.
  58. -- 
  59. Tim McBrayer                                tmcbraye@thor.ece.uc.edu
  60. Computer Architecture Design Laboratory     (513) 556-0904
  61. University of Cincinnati                    "Visualize Whirled Peas"
  62.