home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / std / cplus / 1854 < prev    next >
Encoding:
Internet Message Format  |  1992-12-21  |  1.2 KB

  1. Path: sparky!uunet!nntp1.radiomail.net!fernwood!autodesk!larsn
  2. From: larsn@Autodesk.COM (Lars Nyman)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Must derived class reserve space for an empty base class?
  5. Message-ID: <18184@autodesk.COM>
  6. Date: 18 Dec 92 18:47:33 GMT
  7. References: <1992Dec16.202800.3398@microsoft.com>
  8. Organization: Autodesk Inc., Sausalito CA, USA
  9. Lines: 40
  10.  
  11. jimad@microsoft.com (Jim Adcock) writes:
  12. |class A {};
  13. |
  14. |class B : public A
  15. |{
  16. |public:
  17. |    A a;
  18. |};
  19. |
  20. |main()
  21. |{
  22. |    B b;
  23. |    A* p1; 
  24. |    A* p2;
  25. |
  26. |    p1 = &b;
  27. |    p2 = &(b.a);
  28. |
  29. |    if (p1 == p2)
  30. |        printf("equal %lX %lX\n", (long)p1, (long)p2);
  31. |    else
  32. |        printf("unequal %lX %LX\n", (long)p1, (long)p2);
  33. |
  34. |    return 0;
  35. |}
  36.  
  37. ARM p74:  "Two pointers to the same object compare equal".
  38. ARM p163: "An object of a class consists of a (possibly empty) sequence of 
  39.        members".
  40.  
  41. I don't know if ARM defines what "same object" means.
  42. But, it seems to me a member is a different (i.e. not the same) object than
  43. the "enclosing object".  
  44.  
  45. E.g. using the example above, 'b' is not the same object as 'b.a'.
  46.  
  47. Therefore, according to ARM p74-75, the pointer comparison in the example
  48. above 'p1 == p2' (in effect '((A*) &b) == &b.a') is implementation dependent.
  49.  
  50. Atleast according to my reading of the ARM as it stands today...
  51.