home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: gnu.g++.bug
- Path: sparky!uunet!cis.ohio-state.edu!cse.ucsc.EDU!dlong
- From: dlong@cse.ucsc.EDU (Dean R. E. Long)
- Subject: conversion operator bug?
- Message-ID: <199301040217.AA04377@cypress.ucsc.edu>
- Sender: gnulists@ai.mit.edu
- Organization: GNUs Not Usenet
- Distribution: gnu
- Date: Sun, 3 Jan 1993 10:17:20 GMT
- Approved: bug-g++@prep.ai.mit.edu
- Lines: 38
-
- Should '(B &)a' behave differently than 'a.operator B&()' in the
- example below?
-
- dl
- -------------
- moria /tmp [91] % cat a.c
- #include <iostream.h>
-
- class B {};
-
- class A {
- B *p;
- public:
- A() { p = 0; }
- operator B * () { cout << "Called B*\n"; return p; }
- operator B & () { cout << "Called B&\n"; return *p; }
- };
-
- main()
- {
- A a;
- B &b = (B &)a;
- B *bp = (B *)a;
- B &br = a.operator B&();
- cout.form("&a = %x\n", &a);
- cout.form("&b = %x\n", &b);
- cout.form("bp = %x\n", bp);
- cout.form("&br = %x\n", &br);
- }
- moria /tmp [92] % g++ a.c
- moria /tmp [93] % a.out
- Called B*
- Called B&
- &a = f7fff9b8
- &b = f7fff9b8
- bp = 0
- &br = 0
-
-