home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.sys.sgi:11548 comp.lang.c++:11702
- 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
- Newsgroups: comp.sys.sgi,comp.lang.c++
- Subject: C++ member pointer error
- Message-ID: <1992Jul28.184745.2854@babbage.ece.uc.edu>
- From: tmcbraye@snert.ece.uc.edu (Tim McBrayer)
- Date: Tue, 28 Jul 1992 18:47:45 GMT
- Sender: root@babbage.ece.uc.edu (Operator)
- Organization: Unversity of Cincinnati, ECE Dept
- Nntp-Posting-Host: snert.ece.uc.edu
- Lines: 49
-
- I'm trying to initialize a pointer to a class method and then call a function
- through said pointer. I'm working in C++ on a SGI IRIS. As far as I can
- tell, I'm accessing the pointer properly, according to Stroustrup's book.
- However, when I compile with "CC junk.cc", I get:
-
- "junk.cc", line 21: error: object missing in call through pointer to
- member function
-
- The most frustrating part of this is that the code works under g++ on a
- Sparcstation. Are there any known bugs with SGI C++ with IRIX 4.0.1? Does
- anyone have any idea what 'object' is being referred to in the error
- message?
-
- Example code follows.
-
- #include <iostream.h>
-
- class V{
- public:
- int i;
- V() { i = 0;};
- void run();
- char * print(int x) {cout << "x is " << x << endl; return "Foo!";};
- };
-
- struct E {
- typedef char * (V::*fnptr)(int);
- fnptr fn;
- E() { fn = 0;};
- };
-
- void V::run() {
- E e;
- e.fn = (fnptr) &V::print;
- i = 42;
- cout << (e.fn)(i) << endl; //ERROR: (*(e.fn))(i) gives the same error
- };
-
- int main(){
- V v;
- v.run();
- cout << v.print(5) << endl;
- }
-
- Thanks in advance for any and all help.
- --
- Tim McBrayer tmcbraye@thor.ece.uc.edu
- Computer Architecture Design Laboratory (513) 556-0904
- University of Cincinnati "Visualize Whirled Peas"
-