|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-09-30 10:10:15
From: "Gennadiy Rozental" <gennadiy_at_[hidden]>
> P.S. Cameau onlinr does seems to complain about following code:
> class A {
> public:
> A() {};
> private:
> A( A const& );
> void operator=( A const& );
> };
>
> void foo( A const& )
> {
> }
>
> void moo()
> {
> foo( A() );
> }
>
> Could anybody explain why?
Difficult but I'll try. Rvalues of non-class types don't have addresses as
they can live outside the addressable memory (in registers, for example.)
When a reference is bound to an rvalue, that rvalue may need to be copied to
addressable memory. In a context where 'this' is not used, rvalues of class
types can live outside addressable memory, too.
So the compiler in the above is allowed to use the copy constructor to
create another (addressable) temporary of type 'A' (or 'A const') and bind
the reference to it, instead of binding directly to 'A()' that may not be
addressable.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk