RE: Passing temporary class instantiation as an argument by reference

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Laine,

>Is there a flag or something I can use to get this to compile, or do I have to create a temporary copy of what I'm passing into the member before I call it?

You cannot pass a temporary to a non-const reference.

Why?  Because the non-const reference says "I'm going to modify the object you are passing."  And doing that, generally, does not make sense for a temporary.  Especially since, in C++, you can get temporaries when you didn't expect them.

To fix the problem try this approach: change the parameter from a non-const reference to a const reference.  Or change the parameter to a pass-by-value.

If neither of those are suitable, then remove the temporary that it is passing now, and make an explicit variable, and pass in that variable.

HTH,
--Eljay


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux