home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!yale!gumby!destroyer!cs.ubc.ca!newsserver.sfu.ca!sfu.ca!wong
- From: wong@fraser.sfu.ca (Sam S. Wong)
- Subject: Re: Need help: array of pointers to member functions C++.
- Message-ID: <wong.724531626@sfu.ca>
- Sender: news@sfu.ca
- Organization: Simon Fraser University, Burnaby, B.C., Canada
- References: <wong.724526569@sfu.ca>
- Date: Wed, 16 Dec 1992 18:47:06 GMT
- Lines: 54
-
- Never mind. I figured out the solution.
- I have to cast the the address of that member. Its ugly but it works.
-
- The Solution is:
-
- >-------------------------------------
- >
-
-
- >class dummy {
- > public:
- > int hello(void);
- >};
-
- >int just_hello (void);
-
- >dummy dumb;
- >int (*fnptr[10])(void);
-
-
- >main()
- >{
- > dumb.hello();
- > fnptr[1] = just_hello;
- > (*fnptr[1])();
- > fnptr[1] = (int (*)(void))&dummy::hello; // cast it this way or
- > fnptr[1] = (int (*)(void))&dumb.hello; // this way.
- > (*fnptr[1])();
- >}
-
-
- >int dummy::hello (void)
- >{
- > printf ("\nhello");
- >}
-
-
- >int just_hello (void)
- >{
- > printf ("\njust_hello");
- >}
-
-
- >-----------------------------------------------------
-
-
-
-
-
-
-
-
-
-
-