home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / gnu / g / bug / 2118 < prev    next >
Encoding:
Text File  |  1993-01-03  |  1.0 KB  |  51 lines

  1. Newsgroups: gnu.g++.bug
  2. Path: sparky!uunet!cis.ohio-state.edu!cse.ucsc.EDU!dlong
  3. From: dlong@cse.ucsc.EDU (Dean R. E. Long)
  4. Subject: conversion operator bug?
  5. Message-ID: <199301040217.AA04377@cypress.ucsc.edu>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Sun, 3 Jan 1993 10:17:20 GMT
  10. Approved: bug-g++@prep.ai.mit.edu
  11. Lines: 38
  12.  
  13. Should '(B &)a' behave differently than 'a.operator B&()' in the
  14. example below?
  15.  
  16. dl
  17. -------------
  18. moria /tmp [91] % cat a.c
  19. #include <iostream.h>
  20.  
  21. class B {};
  22.  
  23. class A {
  24.     B *p;
  25. public:
  26.     A() { p = 0; }
  27.     operator B * () { cout << "Called B*\n"; return p; }
  28.     operator B & () { cout << "Called B&\n"; return *p; }
  29. };
  30.  
  31. main()
  32. {
  33.     A a;
  34.     B &b = (B &)a;
  35.     B *bp = (B *)a;
  36.     B &br = a.operator B&();
  37.     cout.form("&a = %x\n", &a);
  38.     cout.form("&b = %x\n", &b);
  39.     cout.form("bp = %x\n", bp);
  40.     cout.form("&br = %x\n", &br);
  41. }
  42. moria /tmp [92] % g++ a.c
  43. moria /tmp [93] % a.out
  44. Called B*
  45. Called B&
  46. &a = f7fff9b8
  47. &b = f7fff9b8
  48. bp = 0
  49. &br = 0
  50.  
  51.