This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Not Const Temporaries


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]