cast(A)b is not an lvalue

Ali Çehreli acehreli at yahoo.com
Wed Dec 26 08:59:00 PST 2012


On 12/26/2012 07:37 AM, Namespace wrote:
 > If I don't comment out line 19 I get:
 > /home/c803/c821.d(19): Error: function c821.foo (ref A a) is not
 > callable using argument types (B)
 > /home/c803/c821.d(19): Error: cast(A)b is not an lvalue
 >
 > Code: http://dpaste.dzfl.pl/89f55c62
 >
 > Should not work all three?

I can answer the question in the subject line without looking at dpaste: 
Yes, in many cases the result of a cast operation is an rvalue. It is a 
temporary that is constructed at the spot for that cast operation.

Imagine casting an int to a double. The four bytes of the int is nowhere 
close to what the bit representation of a double is, so a double is made 
at the spot.

Ali



More information about the Digitalmars-d-learn mailing list