Question regarding template instantiation of tempory type

Eljay Love-Jensen eljay@adobe.com
Mon Nov 15 13:32:00 GMT 2004


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



More information about the Gcc-help mailing list