home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / gnu / g / help / 1223 < prev    next >
Encoding:
Text File  |  1992-09-12  |  1.6 KB  |  49 lines

  1. Newsgroups: gnu.g++.help
  2. Path: sparky!uunet!mcsun!sunic!liuida!isy!isy.liu.se!svan
  3. From: svan@isy.liu.se (Jonas Svanberg)
  4. Subject: Re: how to do this?
  5. Message-ID: <1992Sep12.160053.28778@isy.liu.se>
  6. Keywords: pointer to member
  7. Sender: news@isy.liu.se (Lord of the News)
  8. Reply-To: svan@isy.liu.se
  9. Organization: Linkoping University
  10. References: <92Sep10.203359.4881@acs.ucalgary.ca>
  11. Date: Sat, 12 Sep 1992 16:00:53 GMT
  12. Lines: 35
  13.  
  14. > What is wrong with the
  15. > following constructions and how can I do it in g++?
  16. >
  17. > ----------
  18. >
  19. > class a {
  20. > public: 
  21. >    int x();
  22. > };
  23. >
  24. > int a::x() { return 1; }
  25. >
  26. > main() {
  27. >    printf("%x\n", (int(*))a::x);
  28. > }
  29.  
  30. You're trying to cast a pointer to member to a pointer to object
  31. type. That can't be done according to the standards
  32. documentation I've read over C++ (Annotated C++ Ref. Man. by
  33. Ellis & Stroustrup). 
  34. Pointer to members may even not be explicitly converted to void*!
  35.  
  36. The reason for this is that pointers to members may be
  37. a structure containing both addresses and offsets. There is
  38. no point in allowing a cast to any ordinary pointer.
  39.  
  40. O----------------------------O----------------------------------O
  41. | Jonas Svanberg             | Email: svan@isy.liu.se           |
  42. | Div. of Information Theory O----------------------------------O
  43. | Department of E.E. (ISY)   | "And Noah said to the animals:   | 
  44. | Linkoping University       |  - Go out and multiply!          |  
  45. | S-581 83 Linkoping         |  The snake said:                 |
  46. | SWEDEN                     |  - But how can I? I'm an adder!" |
  47. O----------------------------O----------------------------------O
  48.  
  49.