home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11709 < prev    next >
Encoding:
Text File  |  1992-07-28  |  1.5 KB  |  59 lines

  1. Path: sparky!uunet!sunquest!whm
  2. From: whm@sunquest.UUCP (Bill Mitchell)
  3. Newsgroups: comp.lang.c++
  4. Subject: DEC C++ right or wrong on member pointer construct?
  5. Message-ID: <45110@sunquest.UUCP>
  6. Date: 29 Jul 92 07:47:51 GMT
  7. Organization: Sunquest Information Systems, Tucson
  8. Lines: 49
  9.  
  10. The following program compiles ok with cfront 2.0 and 2.1, but DEC C++
  11. complains (at the line marked "error?"):
  12.  
  13. error: In the initializer for Bpmap[0].Bp::a, "&U::d" is of type "pointer to
  14. Derived member of U", and may not be converted to "pointer to Base member of U".
  15.  
  16.     class Base {
  17.     };
  18.  
  19.     class Derived: public Base {
  20.     };
  21.  
  22.     class U {
  23.       public:
  24.     Derived d;
  25.     };
  26.  
  27.     struct Bp {
  28.     Base U::*a;
  29.     };
  30.  
  31.     struct Bp Bpmap[] = {
  32.     &U::d,  // error?
  33.     0
  34.     };
  35.  
  36. It seems to me that it should be ok because the derived class D should
  37. acceptable in places where the base class B is acceptable.
  38.  
  39. If I try to cast:
  40.  
  41.     struct Bp Bpmap[] = {
  42.     (Base U::*)&U::d,
  43.     0
  44.     };
  45.  
  46. the error is essentially the same:
  47.  
  48. error: In the initializer for Bpmap[0].Bp::a, "(Base ...)&U::d" is of type
  49. "pointer to Derived member of U", and may not be converted to "pointer to
  50. Base member of U".
  51.  
  52. I welcome your comments.
  53. --------------------------------------------------------------------
  54. Bill Mitchell                whm@sunquest.com
  55. Sunquest Information Systems        sunquest!whm@arizona.edu
  56. 4801 E. Broadway                        {arizona,uunet}!sunquest!whm
  57. Tucson, AZ, 85711                       sunquest!whm@uunet.uu.net
  58. 602-570-2585
  59.