This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Question regarding template instantiation of tempory type
- From: Eljay Love-Jensen <eljay at adobe dot com>
- To: Arthur Tse <phyfai at physics dot unimelb dot edu dot au>, gcc-help at gcc dot gnu dot org
- Date: Mon, 15 Nov 2004 07:32:00 -0600
- Subject: Re: Question regarding template instantiation of tempory type
- References: <4198AC97.1030701@physics.unimelb.edu.au>
Hi Arthur,
If your parameters are constant, then you should put in "T const&" for the
parameter type.
If the parameters are being mutated by the function (indicated by the
absence of const), then temporaries are supposed to generate an error
because mutating a temporary is considered a programming error by the
compiler. (There are a few ways to work around this situation, but it
takes a little more work on the invocation side of the fence, and involves
wrapping the temporary with something that returns a non-const reference to
itself.)
HTH,
--Eljay