This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
conversion operator and pass-by-reference
- To: <gcc at gcc dot gnu dot org>
- Subject: conversion operator and pass-by-reference
- From: "Peter Bienstman" <Peter dot Bienstman at rug dot ac dot be>
- Date: Tue, 23 Nov 1999 14:14:05 +0100
Hi,
Consider the following snippet:
struct B {};
struct A
{
operator B() {B b; return b;}
};
void f(B b) {}
void f_ref(B& b) {}
int main()
{
A a;
f(a); // OK
f_ref(a); // doesn't compile
return 0;
}
It is not a problem for the compiler to convert a to a B through the
used-defined conversion operator. However, the logical extension of
converting a to a B& doesn't work.
Is this behaviour as prescribed by the standard, or is it a bug in g++?
Thanks,
Peter
-------------------------------------
Peter Bienstman
Department of Information Technology
INTEC/IMEC - University of Gent
St.-Pietersnieuwstraat 41
B-9000 Gent - Belgium
E-mail: Peter.Bienstman@rug.ac.be
Tel: +32 9 264 3445
Fax: +32 9 264 3593
-------------------------------------