Topic: Address temporary
Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Wed, 7 Sep 1994 04:14:47 GMT Raw View
In article writes:
>We have a bunch of code which takes the address of objects created
>temporarily by explictly called constructors. This does not
>seem to be supported by many compilers, and is of questionable
>legality due to ARM 12.2 ... There are only two things that
>can be done with a temporary...
>
>Wondering if this has changed in the draft standard process, I
>got my draft as of 25 January 1994 and it seems to have sections 12.1 through
>12.4 amputated. It goes from 12.1 paragraph 5 to paragraph 3 apparently of
>section 12.4 with 12.2 and 12.3 nowhere to be found. This is a lot of
>missing material includeing user-defined conversions.
>
>Can anyone add some light?
Its not permitted. Not directly. But you can define
template<class T> T* operator&(const T &x) {
return const_cast<T*>(&x)
}
*&1 = 2; // legal (but useless)
I dont recomment this -- which is why I argued that the built-in
address of operator should take the address of temporaries.
(And do it correctly -- preserve constness, which the above
template doesnt)
--
JOHN (MAX) SKALLER, INTERNET:maxtal@suphys.physics.su.oz.au
Maxtal Pty Ltd,
81A Glebe Point Rd, GLEBE Mem: SA IT/9/22,SC22/WG21
NSW 2037, AUSTRALIA Phone: 61-2-566-2189