🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #1208

conversion operator bug?

#1208
From: Dean R. E. Long
Date: Sun, 03 Jan 1993 10:17
37 lines
1072 bytes
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
Technical Details
Message-ID: <199301040217.AA04377@cypress.ucsc.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!cse.ucsc.EDU!dlong

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!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