This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: Problem with base and derived classes.
- To: Alexander Zvyagin <zvyagin at gams dot ihep dot su>
- Subject: Re: Problem with base and derived classes.
- From: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Date: 30 Aug 1999 15:37:18 -0300
- Cc: gcc-bugs at gcc dot gnu dot org
- References: <Pine.LNX.3.96.990830195228.9732C-100000@gams.ihep.su>
On Aug 30, 1999, Alexander Zvyagin <zvyagin@gams.ihep.su> wrote:
> D d1(B()); // The compiler message is expected here if D is undefined.
This is not a declaration of an object d1, of type D, initialized with
a temporary B(). According to the C++ grammar and disambiguation
rules, this is a declaration of a function named d1, returning a D,
and taking an argument of type `B()', i.e., a pointer (implicitly
inferred) to a function taking no arguments and returning a B.
Exactly as gcc reports:
> file1.c:12: assignment to `A *' from `D (*)(B (*)())'
There are two possible work-arounds. The first, albeit cleaner, has
slightly different semantics, since it relies on copy-construction:
D d1 = B();
In order to perform direct initialization, as you want, a common
disambiguation in favor of an expression initializer, over a type
name, is:
D d1((0,B()));
The extra 0, even being discarded because of the comma operator, tells
the parser an expression follows, and not a type name.
--
Alexandre Oliva http://www.dcc.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
oliva@{dcc.unicamp.br,guarana.{org,com}} aoliva@{acm.org,computer.org}
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
** I may forward mail about projects to mailing lists; please use them