Not Const Temporaries
Alexandre Oliva
aoliva@redhat.com
Thu May 3 04:17:00 GMT 2001
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
More information about the Gcc-help
mailing list