This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Not Const Temporaries
- To: Philippe Cizaire <pci at silicomp dot com>
- Subject: Re: Not Const Temporaries
- From: Alexandre Oliva <aoliva at redhat dot com>
- Date: 03 May 2001 08:15:00 -0300
- Cc: gcc-help at gcc dot gnu dot org
- Organization: GCC Team, Red Hat
- References: <3AF03354.6558@silicomp.com>
On May 2, 2001, Philippe Cizaire <pci@silicomp.com> wrote:
> - it compils and work fine on my solaris :
Which compiler? The compiler is broken, because it accepts invalid
code.
> In function `TKeeper TKeeped::New ()':
> test.cc:80: no matching function for call to `TKeeper::TKeeper
> (TKeeper)'
> test.cc:13: candidates are: TKeeper::TKeeper (TKeeped &)
> test.cc:16: TKeeper::TKeeper (TKeeper &)
The problem is that you've got a temporary of type TKeeper, but a
temporary can't be bound to a non-const reference.
If it's impossible to arrange for the copy constructor to take a const
reference, you'll have to introduce a member function that returns
`*this' by reference, and call it in order to be able to bind the
lvalue to a non-const reference.
--
Alexandre Oliva Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist *Please* write to mailing lists, not to me