home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!enterpoop.mit.edu!senator-bedfellow.mit.edu!bloom-picayune.mit.edu!ceci.mit.EDU!jud
- From: jud@ceci.mit.EDU (Judson Harward)
- Subject: Pointer to members
- Message-ID: <1993Jan5.230617.23557@athena.mit.edu>
- Sender: news@athena.mit.edu (News system)
- Nntp-Posting-Host: ithake.mit.edu
- Organization: "Center for Educational Computer Inintiatives at MIT"
- Date: Tue, 5 Jan 1993 23:06:17 GMT
- Lines: 80
-
-
- The Annotated C++ Reference Manual hedges on the issue of
- generic pointers to members on p. 70:
-
- "There is no equivalent to void * for pointers to members.
- This implies that casting of pointers to pointers to members must
- be used if a generic 'pointer to any member of any class' is needed."
-
- That sounds fairly definite. But then their proposed work around uses
- the following typedef:
-
- typedef void Z::* any_ptom;
-
- any_ptoms are not used in the ARM example, but *any_ptoms are.
- Is there any reason not to support a generic "pointer to any member of any
- class" such as an any_ptom?
-
- The following code works on Sun's version of AT&T 2.1:
-
- #include <stdlib.h>
- #include <iostream.h>
-
- class Dummy;
- typedef void Dummy::*any_ptom;
-
- class X
- {
- public:
- int i;
- X(int j) : i( j ) {};
- };
-
- class Y
- {
- public:
- double d;
- Y(double e) : d( e ) {};
- };
-
- main()
- {
- X x(1);
- Y y(2.0);
- int mI;
- double mD;
- int X::* ptmX;
- double Y::* ptmY;
- any_ptom *paptm;
- any_ptom aptm;
-
- ptmX = &X::i;
- paptm = (any_ptom *) &ptmX;
- mI = x.*(*(int X::**) paptm);
- cout << mI << '\n';
- ptmY = &Y::d;
- paptm = (any_ptom *) &ptmY;
- mD = y.*(*(double Y::**) paptm);
- cout << mD << '\n';
-
- // I don't think the following is supposed to work.
- // Probably shouldn't use it.
- aptm = (any_ptom) &X::i;
- paptm = &aptm;
- mI = x.*(*(int X::**) paptm);
- cout << mI << '\n';
- }
-
- Is the success of the last portion using aptm = (any_ptom) just
- due to a lax compiler?
-
- Any comments would be appreciated. Thanks in advance.
-
- --
- Jud Harward
- AthenaMuse Software Consortium
- Center for Educational Computing Initiatives
- M. I. T.
-
- jud@ceci.mit.edu
- (617-646-8045)
-